HDU1754-ZKW线段树
单点更新,区间最值
HDU 1754
// // Created by helica on 2018/3/18. // //zkw线段树 单点修改 区间求最值 //HDU 1754 #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> using namespace std; const int N = 200000 + 10; int M = 1; int T[N<<2]; void change(int x, int v){ T[M+x] = v; for(int p= (M+x)>>1;p;p>>=1) T[p] = max(T[p<<1], T[p<<1|1]); } int query(int s, int t){ int ans = -1; for (s=M+s-1,t=M+t+1; s^t^1; s>>=1, t>>=1) { if (~s&1) ans = max(ans, T[s^1]); if ( t&1) ans = max(ans, T[t^1]); } return ans; } int main(){ int n,q,op,s,t; while(~scanf("%d %d", &n, &q)){ memset(T, 0, sizeof T); for(M=1;M<n;M<<=1); for (int i=0,tmp;i<n;i++) { scanf("%d", &tmp); change(i+1, tmp); } for(int i=0;i<q;i++){ char op[5]; scanf("%s %d %d", op, &s, &t); if(op[0] == 'U'){ change(s, t); }else if(op[0] == 'Q'){ printf("%d\n", query(s, t)); } } } }