标签:
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 66742 Accepted Submission(s): 25969
1 #include <bits/stdc++.h> 2 #define lrt rt<<1 3 #define rrt rt<<1|1 4 #define lson l, m, lrt 5 #define rson m+1, r, rrt 6 using namespace std; 7 const int maxn = 200005; 8 int maxv[maxn<<2]; 9 int n, q; 10 char op[5]; 11 12 void push_up(int rt){ 13 maxv[rt] = max(maxv[lrt], maxv[rrt]); 14 } 15 16 void build(int l, int r, int rt){ 17 if (l == r){ 18 int num; 19 scanf("%d", &num); 20 maxv[rt] = num; 21 return ; 22 } 23 int m = (l+r)>>1; 24 build(lson); 25 build(rson); 26 push_up(rt); 27 } 28 29 void modify(int p, int val, int l, int r, int rt){ 30 if (l == r){ 31 maxv[rt] = val; 32 return ; 33 } 34 int m = (l+r)>>1; 35 if (p <= m) 36 modify(p, val, lson); 37 else 38 modify(p, val, rson); 39 push_up(rt); 40 } 41 42 int query(int ql, int qr, int l, int r, int rt){ 43 if (ql<=l && r<=qr) 44 return maxv[rt]; 45 int m = (l+r)>>1; 46 int maxr = 0; 47 if (ql <= m) 48 maxr = max(maxr, query(ql, qr, lson)); 49 if (qr > m) 50 maxr = max(maxr, query(ql, qr, rson)); 51 return maxr; 52 } 53 54 int main(){ 55 while (~scanf("%d%d", &n, &q)){ 56 build(1, n, 1); 57 int a, b; 58 while (q--){ 59 scanf("%s%d%d", op, &a, &b); 60 if (op[0] == ‘Q‘) 61 printf("%d\n", query(a, b, 1, n, 1)); 62 else 63 modify(a, b, 1, n, 1); 64 } 65 } 66 return 0; 67 }
标签:
原文地址:http://www.cnblogs.com/Silenceneo-xw/p/5958563.html