BZOJ4419 [Shoi2013]发微博

题面在这里

水……

示例程序:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<cstdio>
#include<set>
#include<algorithm>
using namespace std;

const int maxn=200005;
int n,q,num[maxn],ans[maxn];
set<int> S[maxn];
int main(){
scanf("%d%d",&n,&q);
while (q--){
char c=getchar();while (c!='+'&&c!='-'&&c!='!') c=getchar();
if (c=='!'){
int x;scanf("%d",&x);
num[x]++;
}else
if (c=='+'){
int x,y;scanf("%d%d",&x,&y);
S[x].insert(y); S[y].insert(x);
ans[x]-=num[y]; ans[y]-=num[x];
}else{
int x,y;scanf("%d%d",&x,&y);
S[x].erase(y); S[y].erase(x);
ans[x]+=num[y]; ans[y]+=num[x];
}
}
for (int i=1;i<=n;i++)
for (set<int>::iterator it=S[i].begin();it!=S[i].end();it++)
ans[i]+=num[*it];
for (int i=1;i<=n;i++) printf("%d ",ans[i]);
return 0;
}