Set violence. Recording a rec array indicates how many tweets each person has made, and when the + minus rec,-is added rec can indicate the number of tweets that the person has seen.
Finally, iterate over the set and then add Rec.
#include <iostream>#include<cstdio>#include<cstring>#include<Set>#defineMAXN 200500using namespacestd;Set<int>S[MAXN];intN,M,X,Y,ANS[MAXN],REC[MAXN];Set<int>:: iterator it;Charss[2];voidWork1 () {scanf ("%d",&x); REC[X]++;}voidWork2 () {scanf ("%d%d",&x,&X); S[x].insert (y); S[y].insert (x); ANS[X]-=Rec[y]; Ans[y]-=rec[x];}voidWork3 () {scanf ("%d%d",&x,&y); S[x].erase (y); S[y].erase (x); ANS[X]+=Rec[y]; Ans[y]+=rec[x];}intMain () {scanf ("%d%d",&n,&m); for(intI=1; i<=m;i++) {scanf ("%s", SS); if(ss[0]=='!') Work1 (); Else if(ss[0]=='+') Work2 (); ElseWork3 (); } for(intI=1; i<=n;i++) { for(It=s[i].begin (); It!=s[i].end (); it++) { intnow=*it; Ans[i]+=Rec[now]; } } for(intI=1; i<=n-1; i++) printf ("%d", Ans[i]); printf ("%d\n", Ans[n]); return 0;}
Bzoj 4419 Tweets