Topic
Transmission Door
Sol
Two points + line tree
How could I not have thought of that?
Two-point answer, the number classification, greater than equals \ (mid\) for \ (1\), less than \ (0\)
Equivalent to the \ (01\) sequence, and finally determine whether the query location \ (1\)
Segment Tree +lazy Overlay
# include <bits/stdc++.h># define RG Register# define IL inline# define Fill (A, B) memset (A, B, sizeof (a))using namespaceStdtypedef Long LongllConst int_(1e5+5); ILintInput () {RGintx =0, z =1; RgCharc = GetChar (); for(; c <' 0 '|| C >' 9 '; c = GetChar ()) z = c = ='-'?-1:1; for(; C >=' 0 '&& C <=' 9 '; c = GetChar ()) x = (x <<1) + (x <<3) + (c ^ -);returnx * z;}intN, M, Q, A[_], ql[_], qr[_], qo[_];intSum[_ <<2], Cov[_ <<2];ilvoidBuild (RGintX, RGintL, RGintR, RGintV) {Sum[x] =0, cov[x] =-1;if(L = = r) {Sum[x] = a[l] >= v;return; } RGintMid = (L + r) >>1, ls = x <<1, rs = x <<1|1; Build (LS, l, Mid, V), build (RS, Mid +1, R, v); SUM[X] = Sum[ls] + sum[rs];} ILvoidPushdown (RGintX, RGintL, RGintMid, RGintR) {RGintls = x <<1, rs = x <<1|1; COV[LS] = Cov[rs] = cov[x]; Sum[ls] = (mid-l +1) * Cov[x]; Sum[rs] = (r-mid) * cov[x]; COV[X] =-1;} ILvoidModify (RGintX, RGintL, RGintR, RGintL, RGintR, RGintV) {if(l <= L && R >= R) {Sum[x] = (r-l +1) * V; Cov[x] = v;return; } RGintMid = (L + r) >>1, ls = x <<1, rs = x <<1|1;if(Cov[x]! =-1) pushdown (X, L, Mid, R);if(L <= mid) Modify (LS, L, Mid, L, R, V);if(R > Mid) Modify (RS, Mid +1, R, L, R, v); SUM[X] = Sum[ls] + sum[rs];} ILintQuery (RGintX, RGintL, RGintR, RGintL, RGintR) {if(Cov[x]! =-1)returnCOV[X] * (R-l +1);if(l <= L && R >= R)returnSUM[X]; RgintMid = (L + r) >>1;if(R <= mid)returnQuery (x <<1, L, Mid, L, R);if(L > Mid)returnQuery (x <<1|1, Mid +1, R, L, R);returnQuery (x <<1, L, Mid, L, mid) + Query (x <<1|1, Mid +1, R, Mid +1, R);} ILBOOLCheck (RGintMid) {Build (1,1, N, mid); for(RGinti =1; I <= m; ++i) {RGintCNT = Query (1,1, N, Ql[i], qr[i]);if(!cnt | | cnt = = Qr[i]-Ql[i] +1)Continue;if(Qo[i]) {Modify (1,1, N, Ql[i], Ql[i] + CNT-1,1); Modify (1,1, N, Ql[i] + cnt, qr[i],0); }Else{Modify (1,1, N, Ql[i], Qr[i]-CNT,0); Modify (1,1, N, Qr[i]-cnt +1, Qr[i],1); } }returnQuery (1,1, N, Q, q);}intMain (RGintARGC, RGChar* argv[]) {n = input (), M = input (); for(RGinti =1; I <= N; ++i) A[i] = Input (); for(RGinti =1; I <= m; ++i) Qo[i] = input (), ql[i] = input (), qr[i] = input (); Q = Input (); RgintL =1, R = N, ans =0; while(L <= R) {RGintMid = (L + r) >>1;if(Check (mid)) ans = Mid, L = mid +1;ElseR = Mid-1; } printf ("%d\n", ans);return 0;}
Bzoj4552: [tjoi2016&heoi2016] Sort