1 #include <cstdio>//大白书上说节点数最多有2*n-1个 n为区间长度 2 #include <cstring>//这个题开420000的数组却RE了 换成100W+就过了……sad 3 #include <cstdlib> 4 #include <algorithm> 5 #include <iostream> 6 7 8 using namespace std; 9 10 int st[1048576]; 11 int gr[210000]; 12 13 int max(int x,int y) 14 { 15 return x>=y ? x:y; 16 } 17 18 int creat(int node,int l,int r) 19 { 20 if(l == r) 21 { 22 st[node] = gr[l]; 23 return st[node]; 24 } 25 int m = (l+r)/2; 26 27 st[node] = max(creat(node+node,l,m),creat(node+node+1,m+1,r)); 28 29 return st[node]; 30 } 31 32 int query(int ml,int mr,int node,int l,int r) 33 { 34 if(ml == l && mr == r) 35 return st[node]; 36 int m = (l+r)/2; 37 if(mr <= m) 38 { 39 return query(ml,mr,node+node,l,m); 40 } 41 if(m < ml) 42 { 43 return query(ml,mr,node+node+1,m+1,r); 44 } 45 return max(query(ml,m,node+node,l,m),query(m+1,mr,node+node+1,m+1,r)); 46 } 47 48 int change(int site,int grade,int node,int l,int r) 49 { 50 if(l == r && r == site) 51 { 52 st[node] = grade; 53 return st[node]; 54 } 55 int m = (l+r)/2; 56 if(site <= m) 57 { 58 st[node] = change(site,grade,node+node,l,m); 59 return st[node]; 60 } 61 if(m < site) 62 { 63 st[node] = change(site,grade,node+node+1,m+1,r); 64 return st[node]; 65 } 66 } 67 68 int q[110]; 69 void output(int n) 70 { 71 int t; 72 int s = 0,e = 1; 73 q[0] = 1; 74 int i = 1,j = 1; 75 while(1) 76 { 77 78 t = q[s++]; 79 printf("st[%d] = %d ",t,st[t]); 80 q[e++] = t+t; 81 q[e++] = t+t+1; 82 if(t == n+n-1) break; 83 if(i == j) 84 { 85 i = 1; 86 j *= 2; 87 printf("\n"); 88 } 89 else i++; 90 } 91 } 92 93 int main() 94 { 95 int n,m,T; 96 int i; 97 char order[5]; 98 int l,r; 99 int site ,grade; 100 101 while(scanf("%d %d",&n,&m) != EOF) 102 { 103 for(i = 1;i <= n; i++) 104 scanf("%d",&gr[i]); 105 106 creat(1,1,n); 107 //output(n); 108 109 while(m--) 110 { 111 scanf("%s",order); 112 if(order[0] == 'Q') 113 { 114 scanf("%d %d",&l,&r); 115 printf("%d\n",query(l,r,1,1,n)); 116 //output(n); 117 } 118 else if(order[0] == 'U') 119 { 120 scanf("%d %d",&site,&grade); 121 change(site,grade,1,1,n); 122 //output(n); 123 } 124 } 125 } 126 return 0; 127 }