Description
An l,r graph of n-point m-bars, asking for the number of Unicom blocks in the graph when the number on the edge of [] is reserved.
Input
The first line is four integers n, M, K, type, representing the number of points, number of sides, query, and whether to ask for encryption.
The next m line represents each edge in the diagram.
The next K line, two integer l, R for each line, represents a set of queries. For type=0 test points, L and R that are read in are the L, R for the inquiry, and for type=1 test points, the L and R for each group should be L XOR Lastans and R xor Lastans.
Output
K lines each line of an integer represents the number of unicom blocks queried by the group.
Sample Input3 5 4 0
1 3
1 2
2 1
3 2
2 2
2 3
1 5
5 5
1 2
Sample Output2
1
3
1
HINT
For 100% of data, 1≤n, M, k≤200,000.
Puzzle: Http://hzwer.com/4358.htmlcode:
1#include <cstdio>2#include <iostream>3#include <cmath>4#include <cstring>5#include <algorithm>6 using namespacestd;7 Charch;8 BOOLOK;9 voidReadint&x) {Ten for(ok=0, Ch=getchar ();! IsDigit (CH); Ch=getchar ())if(ch=='-') ok=1; One for(x=0; isdigit (ch); x=x*Ten+ch-'0', ch=GetChar ()); A if(OK) x=-x; - } - Const intmaxn=400005; the Const intMaxnode=4000000; - Const intinf=2147483647; - intN,m,q,type,a[maxn],b[maxn],l,r,pos[maxn],pop[maxn],root[maxn],ans; - structlct{ + intson[maxn][2],FA[MAXN],VAL[MAXN],MINV[MAXN],POS[MAXN],ID[MAXN],REV[MAXN]; - voidInitintXintVinti) {val[x]=minv[x]=v,pos[x]=id[x]=i;} + intWhich (intx) {returnson[fa[x]][1]==x;} A BOOLIsRootintx) {returnson[fa[x]][0]!=x&&son[fa[x]][1]!=x;} at voidReverseintx) {if(x) rev[x]^=1;} - voidPushdown (intx) {if(Rev[x]) swap (son[x][0],son[x][1]), Reverse (son[x][0]), Reverse (son[x][1]), rev[x]=0;} - voidRelaxintx) {if(!isroot (x)) relax (fa[x]); Pushdown (x);} - voidUpdateintXintY) {if(Minv[x]>minv[y]) minv[x]=minv[y],pos[x]=pos[y];} - voidUpdateintx) { -minv[x]=val[x],pos[x]=Id[x]; in if(son[x][0]) Update (x,son[x][0]); - if(son[x][1]) Update (x,son[x][1]); to } + voidRotateintx) { - intY=fa[x],z=fa[y],d=which (x), dd=which (y); thefa[son[x][d^1]]=y,son[y][d]=son[x][d^1],fa[x]=Fa[y]; * if(!isroot (y)) son[z][dd]=x; $son[x][d^1]=y,fa[y]=x,update (y), update (x);Panax Notoginseng } - voidSplay (intx) { the relax (x); + while(!isroot (x)) { A if(IsRoot (fa[x])) rotate (x); the Else if(which (x) = =which (fa[x]) rotate (fa[x]), rotate (x); + Elserotate (x), rotate (x); - } $ } $ voidAccessintx) { for(intp=0; x;x=fa[x]) splay (x), fa[son[x][1]=p]=x,update (p=x);} - voidMake_root (intx) {Access (x), splay (x), reverse (x);} - intFindintx) { the access (x), splay (x); - for(; son[x][0];x=son[x][0]) pushdown (x);Wuyi returnx; the } - intQueryintXinty) { Wu if(Find (x) ==find (y)) {make_root (x), Access (y), splay (y);returnpos[y];} - Else return 0; About } $ voidCutintXintY) {make_root (x), Access (y), splay (y), fa[x]=0, son[y][0]=0;} - voidLinkintXintY) {make_root (x), fa[x]=y;} - }LCT; - structseg{ A inttot,sum[maxnode],son[maxnode][2]; + voidInsertintPint&k,intLintRintx) { thesum[k=++tot]=sum[p]+1; - if(L==R)return; $ intM= (l+r) >>1; the if(x<=m) son[k][1]=son[p][1],insert (son[p][0],son[k][0],l,m,x); the Elseson[k][0]=son[p][0],insert (son[p][1],son[k][1],m+1, r,x); the } the intQueryintKintLintRintx) { - if(L==R)returnSum[k]; in intM= (l+r) >>1; the if(x<=m)returnQuery (son[k][0],l,m,x); the Else returnsum[son[k][0]]+query (son[k][1],m+1, r,x); About } the intQueryintAintBintx) {returnQuery (b,0, m,x)-query (A,0, m,x);} the }t; the intMain () { + Read ( N), read (m), read (q), read (type); - for(intI=1; i<=n;i++) Lct.init (I,inf,0); the for(intI=1; i<=m;i++) Lct.init (n+i,i,i);Bayi for(intI=1; i<=m;i++){ the read (A[i]), read (B[i]); the if(a[i]!=B[i]) { -pop[i]=lct.query (A[i],b[i]); - if(Pop[i]) lct.cut (a[pop[i]],pop[i]+n), Lct.cut (b[pop[i]],pop[i]+n); theLct.link (A[i],n+i), Lct.link (b[i],n+i); the } the Elsepop[i]=i; the } - for(intI=1; i<=m;i++) T.insert (root[i-1],root[i],0, M,pop[i]); the while(q--){ the Read (l), read (r); the if(type) l^=ans,r^=ans;94Ans=n-t.query (root[l-1],root[r],l-1); theprintf"%d\n", ans); the } the return 0;98}
Bzoj3514:codechef MARCH14 GERALD07 Enhanced Edition