暑假对STL的学习用法

map

map<int,int> s;

map<int,vector<int> > s;

map<int,list<int> > s;

这些就是map的初始化法子,前面那个就相当于数组下标,后面的就是键值了,可以用它搞二维数组就像第二 三个一样。

然后就是他的用处,他可以自动排序,但是是按照前面的key值排序,就是下标拉,不过看你怎么用这个东西,这个排序用处是有的。

然后就是其他的那些方法

 

 穿插一个函数upper_bound(这个函数是二分可以返回第一个大与你找的数字的下标)就是二分地左边界一,lower_bound(这个是返回第一个大于或等于目标数的下标)就是二分的右边界。这个就是可以让你不用打二分的函数,但是还是建议去学习二分。

 

然后就是操练了

 很简单的题。。

只要你熟悉map的使用就行

复制代码
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
//#define int long long
using namespace std;
const int N=1e5+5;

int32_t main()
{
    map<int,list<int> > a,b;
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        int x,y;
        cin>>x>>y;
        a[x].push_back(y);
        b[y].push_back(x);
    }
    int c,d;
    while (m--)
    {
        cin>>c>>d;
        if(c==0)
        {
            cout<<a[d].size()<<endl;
            for(auto i:a[d])  b[i].remove(d);
            a[d].clear();
        }
        else
        {
            cout<<b[d].size()<<endl;
            for(auto i:b[d]) a[i].remove(d);
            b[d].clear();
        }
    }
    return 0;
}
复制代码

 

 

 

posted @   whatdo+  阅读(8)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示