Line tree, we see a look at it, this problem is a template problem, I learn zkw line segment tree used. Single point of Maintenance, Interval max.
The topic is the loyalty of TYVJ 2.
#include"iostream"#include"Cstdio"using namespacestd;intM;intt[10000000];intRead () {CharC=GetChar (); intA=0; while(c<'0'|| C>'9') c=GetChar (); while(c>='0'&&c<='9') {a=a*Ten+c-'0'; C=GetChar (); } returnA;}voidBuild (intN) { for(m=1; m<=n+1; m*=2);//m indicates the total number of nodes (branch + root), of course, here is the default he is full of two fork tree for(intI=1+m; i<=n+m; i++) t[i]=read (); for(intj=n-1; I i--) T[i]=min (t[i*2],t[i*2+1]);}intAskintAintb) { intans=111111117; //cout << 1 << endl; for(a=a+m-1, b=b+m+1; a^b^1; A/=2, b/=2) { //change the query interval from [s,t] to (s-1,t+1) for easy handling//s^t^1 If =0 then s and T only the last one is different, that is, s and t have a father if(a%2==0) Ans=min (ans,t[a^1]);//If S is the left subtree, the maximum value is the original maximum and the big one in the right subtree. if(b%2==1) Ans=min (ans,t[b^1]);//vice versa } returnans;}voidChangeintXinty) { for(t[x+=m]=y,x/=2; X X/=2) T[x]=min (t[2*x],t[2*x+1]); }intMain () {intn,m; M=read (); n=read (); Build (m); for(intI=1; i<=n; i++) { intA=read (), X=read (), y=read (); if(a==1) {cout << ask (x, y) <<' '; } Else{change (x, y); } } return 0;}
Back Gear | Loyal 2|zkw line tree