BZOJ1103[POI2007] Metropolitan Meg
Test instructions
An n-point tree, the root node is 1, the initial time all edges for the soil road, a total of n-m+1 operations, each can be a side to the road or root node to a node how many dirt road. n,m≤250000
Exercises
First find the DFS sequence, enter the node at the time point of the weight of 1, leaving the node at the time point of the weight of 1, if the road turned into a dirt road will be the left end of the edge of the entry time weights and departure time weights are set to 0, if asked the output node into the time prefix and. Prefixes and modifications can be maintained with a tree-like array.
Code:
1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <queue>5 #defineInc (I,J,K) for (int i=j;i<=k;i++)6 #defineMAXN 2505007 #defineLB (x) x&-x8 using namespacestd;9 Ten structe{intT,n;}; e ES[MAXN];intg[maxn],ess; One voidPeintFintt) { AEs[++ess]= (e) {t,g[f]}; g[f]=ess; - } - intst[maxn*2],l[maxn],r[maxn],tim; the voidDfsintx) { -St[++tim]=x; l[x]=Tim; - for(intI=g[x];i;i=ES[I].N) DFS (es[i].t); -St[++tim]=x; r[x]=Tim; + } -InlineintRead () { + CharCh=getchar ();intf=1, x=0; A while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; Ch=GetChar ();} at while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); - returnf*x; - } - intc[maxn*2],n; - voidUpdateintXintV) { while(x<=n*2) c[x]+=v,x+=lb (x);} - intQueryintx) {intq=0; while(x) q+=c[x],x-=lb (x);returnq;} in intMain () { -N=read (); Inc (I,1, N-1){intA=read (), b=read (); PE (A, b);} toDfs1); Inc (I,1, n) update (L[i],1), Update (r[i],-1); + intM=read ();Charopt[3]; -Inc (I,1, n+m-1){ thescanf"%s", opt); * if(opt[0]=='W'){intA=read (); printf"%d\n", query (L[a])-1);} $ if(opt[0]=='A'){intA=read (), B=read (); Update (l[b],-1); Update (R[b],1);}Panax Notoginseng } - return 0; the}
20160608
BZOJ1103[POI2007] Metropolitan Meg