The puzzle: hahaha I had!!! Chairman Tree + Tree-like array it's really hentai.
Here must share one of my sand tea mistake!!! Look at this code:
void Get (int x,int d) { if(!d)for (lt[ltot=1]=root[x];x;x-=x &-x)if(c[x]) lt[++ltot]=c[x]; Else for (rt[rtot=1]=root[x];x;x-=x&-x) if (C[x]) rt[++rtot]=c[x]; return ;}
Sounds normal, doesn't it? And the indentation is also very beautiful right!!!
But!!!!!!!! Wo Meng found it was wrong!!!!!!!!!!
Because the next else is paired with the above if!!!!!! So this procedure is actually like this:
void get ( int x,int D) { if (!d) for (Lt[ltot=1 ]=root[x];x;x-=x&-x) { if (C[x]) lt[++ltot]=c[x]; else { for (Rt[rtot=1 ]=root[x];x;x-=x&- x) if (c[x]) rt[++rtot]=c[x]; }} return ;}
I'm going crazy,!!!!!!!!!!!!!!!!!!!.
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <queue>6#include <cstring>7 #definePAU Putchar (")8 #defineENT Putchar (' \ n ')9 #defineCH for (int d=0;d<2;d++) if (Ch[d])Ten #defineLson ls (x), y->ch[0],l,m One #defineRson RS (x), Y->ch[1],m+1,r A using namespacestd; - Const intmaxn=100000+Ten, maxnode=20000000+Ten, inf=-1u>>1, vl=1, vr=100000; - structnode{ thenode*ch[2];intSiz;node () {siz=0;} -}POL[MAXNODE],*NODECNT=POL,*ROOT[MAXN],*C[MAXN],*LT[MAXN],*RT[MAXN];intLtot,rtot; -Node*ls (node*x) {returnx?x->ch[0]:x;} -Node*rs (node*x) {returnx?x->ch[1]:x;} + intSZ (node*x) {returnX?x->siz:0;} - intN,M,A[MAXN],CV; + voidBuildintVintPos,node*x,node*&y,intL=VL,intR=VR) { AY=nodecnt++;y->siz=sz (x) +v;if(L==R)return;intM=l+r>>1; at if(pos<=m) y->ch[1]=rs (x), build (V,pos,lson);Elsey->ch[0]=ls (x), build (V,pos,rson);return; - } - voidUpdateintXintv) { - for(intW=X;W<=N;W+=W&-W) Build (-1, A[x],c[w],c[w]); - for(intW=X;W<=N;W+=W&-W) Build (1, A[x]=v,c[w],c[w]);return; - } in void Get(intXintd) { - if(!d) { for(lt[ltot=1]=root[x];x;x-=x&-x)if(C[x]) lt[++ltot]=c[x];} to Else{ for(rt[rtot=1]=root[x];x;x-=x&-x)if(C[x]) rt[++rtot]=c[x];}return; + } -InlineintRead () { the intx=0, sig=1;CharCh=GetChar (); * for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') sig=0; $ for(; isdigit (ch); Ch=getchar ()) x=Ten*x+ch-'0';Panax Notoginseng returnsig?x:-x; - } theInlinevoidWriteintx) { + if(x==0) {Putchar ('0');return;}if(x<0) Putchar ('-'), x=-x; A intlen=0, buf[ the]; while(x) buf[len++]=x%Ten, x/=Ten; the for(inti=len-1; i>=0; i--) Putchar (buf[i]+'0');return; + } - voidinit () { $N=read (); m=read (); $ for(intI=1; i<=n;i++) Build (1, A[i]=read (), root[i-1],root[i]); - return; - } the voidWork () { - intx,y,v;Wuyi while(m--){ the if(!read ()) X=read (), v=read (), update (X,V); - Else{X=read (); Y=read (); v=read (); Wu Get(X-1,0);Get(Y,1);intL=vl,r=vr,m,kth; - while(L<r) {m=l+r>>1; kth=0;//printf ("%d%d%d%d\n", l,r,ltot,rtot); About for(intI=1; i<=ltot;i++) kth-=sz (LS (lt[i)); $ for(intI=1; i<=rtot;i++) kth+=sz (LS (rt[i)); - if(KTH>=V) {r=M; - for(intI=1; i<=ltot;i++) lt[i]=ls (lt[i]); - for(intI=1; i<=rtot;i++) rt[i]=ls (rt[i]); A}Else{l=m+1; v-=kth; + for(intI=1; i<=ltot;i++) lt[i]=RS (lt[i]); the for(intI=1; i<=rtot;i++) rt[i]=RS (rt[i]); - } $ }write (L); ENT; the } the } the return; the } - voidprint () { in return; the } the intMain () {init (); work ();p rint ();return 0;}
COJ 0986 WZJ Data structure (negative 14) interval Dynamic K-Large