cf704A

队列的运用,值得学习

#include<bits/stdc++.h>
using namespace std;
const int maxn=300000+5;
queue<int> e[maxn];
queue<pair<int,int> >Q;
bool mark[maxn];
int n,q;
int main()
{
    memset(mark,false,sizeof(mark));
    int type,x,index=1,ans=0;
    cin>>n>>q;
    while(q--){
        cin>>type>>x;
        if(type==1) {
            Q.push({index++,x});
            e[x].push(index-1);
            ans++;
            cout<<ans<<endl;
        }
        else if(type==2){
            while(!e[x].empty()){
                int u=e[x].front();
                e[x].pop();
                if(!mark[u]) ans--;
                mark[u]=true;
            }
            cout<<ans<<endl;
        }
        else {
            while(!Q.empty()&&Q.front().first<=x){
                int f=Q.front().first,s=Q.front().second;
                Q.pop();
                if(!mark[f]){
                    mark[f]=true;
                    ans--;
                }
            }
            cout<<ans<<endl;
        }
    }
}

猜你喜欢

转载自www.cnblogs.com/033000-/p/10301156.html