CodeForces 705C Thor

时间:2023-03-09 09:42:37
CodeForces 705C Thor

开30W个vector将数字归类,每一类数字开一个指针P,记录已经阅读到哪一个了,还可以开一个优先队列维护这些指针P。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
inline int read()
{
char c = getchar(); while(!isdigit(c)) c = getchar();
int x = ;
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
return x;
} const int maxn=+;
vector<int>g[maxn];
int n,q,sz,p[maxn],ans; struct X
{
int num,now,pos,idx;
bool operator < (const X &a) const {
return idx>a.idx;
}
X(int Num,int Now,int Pos,int Idx) {num=Num; now=Now; pos=Pos,idx=Idx;}
};
priority_queue<X>Q; int main()
{
scanf("%d%d",&n,&q);
sz=; ans=; memset(p,-,sizeof p);
for(int i=;i<=q;i++)
{
int t,d; scanf("%d%d",&t,&d);
if(t==)
{
++sz;
if(p[d]==g[d].size()-)
{
Q.push(X(d,p[d],p[d]+,sz));
}g[d].push_back(sz); ans++;
}
else if(t==)
{
ans=ans-(g[d].size()--p[d]);
p[d]=g[d].size()-;
}
else
{
while(!Q.empty()&&Q.top().idx<=d)
{
X h=Q.top(); Q.pop();
if(h.now<p[h.num]) continue;
ans=ans-(h.pos-p[h.num]);
p[h.num]=h.pos;
if(p[h.num]+<g[h.num].size())
Q.push(X(h.num,p[h.num],p[h.num]+,g[h.num][p[h.num]+]));
}
}
printf("%d\n",ans);
}
return ;
}