N<=1e5 a number, do m<=1e5 operation: The number of the first Li to Ri ascending/descending row, the number of the last Q digit.
There seems to be no data structure to do this? But you can turn to the question of judgment. That is, it is impossible to sort a number of numbers, but a 01-string sequence can be done by a line tree.
So two minutes an answer, than it is small (and so on) the number of 0, than it is 1, if the last Q bit 0 is not a problem to try a smaller number, if it is 1 will have to adjust the size.
The number of segment trees in the interval 1 can be.
1#include <stdio.h>2#include <string.h>3#include <stdlib.h>4#include <algorithm>5 //#include <iostream>6 using namespacestd;7 8 intn,m,q;9 #defineMAXN 200011Ten intA[MAXN];BOOLNOW[MAXN]; One structSMT A { - structNode - { the intnum; - intbe ; - intL,r; - intLs,rs; +}a[maxn<<1]; - intsize; + voidUpintx) A { at Const int&p=a[x].ls,&q=a[x].rs; -a[x].num=a[p].num+A[q].num; - } - voidBesingle (intXBOOLv) - { -A[x].be=v; ina[x].num=v?a[x].r-a[x].l+1:0; - } to voidDownintx) + { - if(!x)return; the Const int&p=a[x].ls,&q=a[x].rs; * if(a[x].be!=-1) $ {Panax Notoginseng Besingle (p,a[x].be); - Besingle (q,a[x].be); thea[x].be=-1; + } A } the voidBuildint&x,intLintR) + { -x=++size; $A[x].l=l;a[x].r=R; $a[x].be=-1; - if(L==R) {a[x].num=now[l];a[x].ls=a[x].rs=0;return;} - Const intMid= (l+r) >>1; the build (A[x].ls,l,mid); -Build (a[x].rs,mid+1, R);Wuyi Up (x); the } - voidbuild () Wu { -Size=0; About intX;build (x,1, n); $ } - intql,qr,v; - voidDenintx) - { A if(QL<=A[X].L && A[X].R<=QR) {Besingle (x,v);return;} + Down (x); the Const intMid= (A[X].L+A[X].R) >>1; - if(ql<=mid) be (A[X].LS); $ if(qr>mid) be (a[x].rs); the Up (x); the } the voidDenintLintRBOOLv) the { -Ql=l;qr=r; This->v=v; inDen1); the } the intQueryintx) About { the if(QL<=A[X].L && A[X].R<=QR)returnA[x].num; the Down (x); the Const intMid= (A[X].L+A[X].R) >>1; + intans=0; - if(Ql<=mid) ans+=query (A[X].LS); the if(qr> mid) ans+=query (a[x].rs);Bayi returnans; the } the intQueryintLintR) - { -Ql=l;qr=R; the returnQuery1); the } the }t; the structDOO - { the intTy,l,r; the }DOO[MAXN]; the voidPlayinti)94 { the inttmp=t.query (DOO[I].L,DOO[I].R); the if(doo[i].ty) the {98t.be (doo[i].l,doo[i].l+tmp-1,1); AboutT.be (DOO[I].L+TMP,DOO[I].R,0); - }101 Else102 {103t.be (doo[i].r-tmp+1, DOO[I].R,1);104T.be (Doo[i].l,doo[i].r-tmp,0); the }106 }107 BOOLCheckintx)108 {109 for(intI=1; i<=n;i++) now[i]= (a[i]>x); the t.build ();111 for(intI=1; i<=m;i++) the {113 Play (i); the } the return!t.query (q,q); the }117 intMain ()118 {119scanf"%d%d",&n,&m); - for(intI=1; i<=n;i++) scanf ("%d",&a[i]);121 for(intI=1; i<=m;i++) scanf ("%d%d%d",&doo[i].ty,&doo[i].l,&DOO[I].R);122scanf"%d",&q);123 intL=1, r=n+1;124 while(l<R) the {126 Const intMid= (l+r) >>1;127 if(Check (mid)) R=mid; - ElseL=mid+1;129 } theprintf"%d\n", L);131 return 0; the}View Code
BZOJ4552: [tjoi2016&heoi2016] Sort