1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 using namespace std;
5
6 const int MaxSize=2000001;
7
8 struct Node
9 { int left,right,mid;
10 int max;
11 }itree[MaxSize*3];
12
13 int nu[MaxSize];
14
15 int Build(int l,int r,int num)
16 { itree[num].left=l;
17 itree[num].right=r;
18 itree[num].mid=(l+r)>>1;
19 if(l==r)
20 { return itree[num].max=nu[l];
21 }
22
23 int lm=Build(l,itree[num].mid,num<<1);
24 int rm=Build(itree[num].mid+1,r,(num<<1)+1);
25 return (itree[num].max=lm>rm?lm:rm);
26 }
27
28 void Update(int id,int val,int num)
29 { if(itree[num].left==itree[num].right)
30 { itree[num].max=val;
31 return;
32 }
33
34 if(id<=itree[num].mid)
35 Update(id,val,num<<1);
36 else
37 Update(id,val,(num<<1)+1);
38 itree[num].max=itree[num<<1].max>itree[num*2+1].max?itree[num<<1].max:itree[num*2+1].max;
39 }
40
41 int Query(int l,int r,int num)
42 { if(itree[num].left==l&&itree[num].right==r)
43 return itree[num].max;
44 if(r<=itree[num].mid)
45 return Query(l,r,num<<1);
46 if(l>itree[num].mid)
47 return Query(l,r,num*2+1);
48 int lm=Query(l,itree[num].mid,num<<1);
49 int rm=Query(itree[num].mid+1,r,num*2+1);
50 return lm>rm?lm:rm;
51 }
52
53 int main()
54 { int N,M;
55 while(scanf("%d%d",&N,&M)!=EOF)
56 { for(int i=1;i<=N;i++)
57 scanf("%d",ν[i]);
58
59 Build(1,N,1);
60 char c[100];
61 int a,b;
62 for(int i=1;i<=M;i++)
63 { scanf("%s%d%d",c,&a,&b);
64 if(c[0]=='Q')
65 printf("%d\n",Query(a,b,1));
66 else
67 Update(a,b,1);
68 }
69 }
70 return 0;
71 }