Interval update + statistical update length
Just a little bit of attention, T.
#include <bits/stdc++.h>#defineLson L, M, rt<<1#defineRson m+1, R, rt<<1|1using namespacestd;Const intMAXN =100000+131;intma[maxn<<2], mi[maxn<<2], lazy[maxn<<2];intCnt;voidPushup (intRT) {Ma[rt]= Max (ma[rt<<1], ma[rt<<1|1]); MI[RT]= Min (mi[rt<<1], mi[rt<<1|1]);}voidPushdown (intRT) { if(LAZY[RT]! =-1) {Lazy[rt<<1] = lazy[rt<<1|1] =Lazy[rt]; Ma[rt<<1] = ma[rt<<1|1] =Lazy[rt]; Mi[rt<<1] = mi[rt<<1|1] =Lazy[rt]; LAZY[RT]= -1; }}voidBuild (intLintRintRT) {Ma[rt]= Mi[rt] =0; LAZY[RT]= -1; if(L = = r)return ; intm = (L + r) >>1; Build (Lson), build (Rson);}voidQuery (intLintRintValintLintRintRT) { //////////////////////////////////// if(l <= l && R <=R) {if(Val < mi[rt])return ; if(Val >=Ma[rt]) {Ma[rt]= Mi[rt] =Val; LAZY[RT]=Val; Cnt+ = R-l +1; return ; } if(L = = r)return ; } ///////////////////////////////////////pushdown (RT); intm = (L + r) >>1; if(L <=m) Query (L, R, Val, Lson); if(R >m) Query (L, R, Val, Rson); Pushup (RT);}intMain () {intT; scanf ("%d",&t); while(t--) { intN; scanf ("%d",&N); Cnt=0; Build (1,100000,1); intL, R, Val; for(inti =0; I < n; ++i) {scanf ("%d%d%d",&l,&r,&val); R--; Query (L,r,val,1,100000,1); } printf ("%d\n", Cnt); } return 0;}
LA 4108 (segment tree)