Bzoj
Luogu
Sol
Obviously it's bad for n different numbers to handle the sort.
What is the convenience of handling it? Only 0 or 1?
A two-part answer \ (mid\), set all the numbers less than equals \ (mid\) to 1, and the number greater than \ (mid\) to all set to 0.
Then just sort it out as required. The sequence of 01 sequences is maintained with the line segment tree, I believe everyone will.
Finally, as long as the (q\) location of the number is not 1 on the line.
Complexity \ (O (m\log{n}) \)
Code
#include <cstdio>#include <cstring>#include <algorithm>using namespaceStdintGI () {intx=0, w=1;CharCh=getchar (); while((ch<' 0 '|| Ch>' 9 ') &&ch!='-') Ch=getchar ();if(ch=='-') w=0, Ch=getchar (); while(ch>=' 0 '&&ch<=' 9 ') x= (x<<3) + (x<<1) +ch-' 0 ', Ch=getchar ();returnW?x:-x;}Const intN =1e5+5;structnode{intOp,l,r;} Q[n];intn,m,a[n],p,l,r,mid,tag[n<<2],sum[n<<2];voidPushup (intx) {sum[x]=sum[x<<1]+sum[x<<1|1];}voidCoverintXintLintRintOPT) {if(opt) sum[x]=r-l+1, tag[x]=1;Elsesum[x]=0, tag[x]=0;}voidPushdown (intXintLintR) {if(tag[x]==-1)return;intMid=l+r>>1; Cover (x<<1, L,mid,tag[x]); cover (x<<1|1, mid+1, R,tag[x]); tag[x]=-1;}voidBuildintXintLintR) {tag[x]=-1;if(L==R) {sum[x]= (A[l]<=mid);return;}intMid=l+r>>1; Build (x<<1, l,mid); Build (x<<1|1, mid+1, R); Pushup (x);}voidModifyintXintLintRintQlintQrintOPT) {if(L>=QL&&R<=QR) {cover (x,l,r,opt);return;} Pushdown (X,L,R);intMid=l+r>>1;if(ql<=mid) Modify (x<<1, l,mid,ql,qr,opt);if(qr>mid) Modify (x<<1|1, mid+1, r,ql,qr,opt); Pushup (x);}intQueryintXintLintRintQlintQR) {if(L>=QL&&R<=QR)returnSUM[X]; Pushdown (X,L,R);intMid=l+r>>1, s=0;if(Ql<=mid) S+=query (x<<1, L,MID,QL,QR);if(Qr>mid) S+=query (x<<1|1, mid+1, R,QL,QR);returns;}BOOLCheck () {Build (1,1, n); for(intI=1; i<=m;++i) {intTmp=query (1,1, N,Q[I].L,Q[I].R);if(tmp==0|| Tmp==q[i].r-q[i].l+1)Continue;if(!Q[I].OP) {Modify (1,1, n,q[i].l,q[i].l+tmp-1,1); Modify1,1, N,Q[I].L+TMP,Q[I].R,0); }Else{Modify (1,1, N,q[i].l,q[i].r-tmp,0); Modify1,1, n,q[i].r-tmp+1, Q[I].R,1); } }returnQuery1,1, n,p,p);}intMain () {N=gi (); M=gi (); for(intI=1; i<=n;++i) A[i]=gi (); for(intI=1; i<=m;++i) q[i]= (node) {gi (), GI (), GI ()}; P=gi (); L=1; R=n; while(L<r) {mid=l+r>>1;if(check ()) R=mid;ElseL=mid+1; } printf ("%d\n", L);return 0;}
[BZOJ4552] [tjoi2016&&heoi2016] Sort