[ABC278C] FF 题解

· · 题解

思路:map 套 set(其实 stack 等 STL 容器都行),用 set 来记录哪些人关注了下标为 i 的人。

代码如下:

#include<bits/stdc++.h>
using namespace std;
int n,q;
unordered_map<int,unordered_set<int>>a; 
int main(){
    cin>>n>>q;
    while(q--){
        int op,x,y;
        cin>>op>>x>>y;
        switch(op){
            case 1://关注
                a[x].insert(y);
                break;
            case 2://取关
                a[x].erase(y);
                break;
            case 3:
                cout<<(a[x].count(y)&&a[y].count(x)?"Yes\n":"No\n");
        }
    }
    return 0;
}