1#include <iostream>2#include <cstdio>3 4 using namespacestd;5 6 intan[200010];7 structNode8 {9 intl;Ten intR; One intMa; A}bn[800010]; - - voidBuildintKintLintR) the { -Bn[k].l=l; -Bn[k].r=R; - if(l==R) + { -Bn[k].ma=An[l]; + return ; A } at intlk=k*2; - intrk=lk+1; - intMid= (L+R)/2; - build (Lk,l,mid); -Build (rk,mid+1, R); -Bn[k].ma=Max (bn[lk].ma,bn[rk].ma); in } - to voidChangeintKintIinta) + { - if(bn[k].l==i&&bn[k].r==i) the { *Bn[k].ma=A; $ return ;Panax Notoginseng } - intlk=k*2; the intrk=lk+1; + if(bn[lk].r>=i) A Change (lk,i,a); the Else if(bn[rk].l<=i) + Change (rk,i,a); -Bn[k].ma=Max (bn[lk].ma,bn[rk].ma); $ } $ - intSearchintKintLintR) - { the if(bn[k].l==l&&bn[k].r==R) - {Wuyi returnbn[k].ma; the } - intlk=k*2; Wu intrk=lk+1; - if(bn[lk].r>=R) About returnsearch (lk,l,r); $ Else if(bn[rk].l<=l) - returnsearch (rk,l,r); - Else - returnMax (Search (LK,L,BN[LK].R), search (rk,bn[rk].l,r)); A } + the intMain () - { $ intn,m; the while(SCANF ("%d%d", &n,&m)! =EOF) the { the for(intI=1; i<=n;i++) thescanf"%d",&an[i]); -Build1,1, n); in for(intI=0; i<m;i++) the { the CharCA; About intb; thescanf"%c",&CA); thescanf"%d%d",&a,&b); the if(ca=='Q') +printf"%d\n", Search (1, A, b)); - Else if(ca=='U') theChange1, A, b);Bayi } the } the return 0; -}
View Code
Point modification interval Query HDU1754