AT_abc366_c 的题解
(一)
动态统计袋中每个数的出现个数和不同的数的个数。
当一个数出现个数从 \(0\) 加到 \(1\) 时,不同的数个数 \(+1\),从 \(1\) 减到 \(0\) 时,不同的数个数 \(-1\)。
具体看代码,挺好理解的。
(二)
AC 代码。
#include<bits/stdc++.h>
#define db double
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define pii pair<int,int>
using namespace std;
inline int read(){
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
}
int ans,vis[1000010];
signed main(){
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int T=read();
while(T--){
int op=read();
if(op==3)printf("%d\n",ans);
if(op==1){
int x=read();
if(!vis[x])ans++;
vis[x]++;
}
if(op==2){
int x=read();
vis[x]--;
if(!vis[x])ans--;
}
}
return 0;
}