1 #include <map>
2 #include <set>
3 #include <queue>
4 #include <cmath>
5 #include <cstdio>
6 #include <iostream>
7 #include <algorithm>
8 using namespace std;
9 #define ref(i,x,y)for(int i=x;i<=y;++i)
10 int read()
11 {
12 char c=getchar();int d=0,f=1;
13 for(;c<‘0‘||c>‘9‘;c=getchar())if(c==‘-‘)f=-1;
14 for(;c>=‘0‘&&c<=‘9‘;d=d*10+c-48,c=getchar());
15 return d*f;
16 }
17 const int N=500001;
18 int n,m,ANS,a[N],b[N];
19 set<int> s;
20 map<int,int> mp;
21 priority_queue<int,vector<int>,greater<int> > q;
22 void Insert(int y)
23 {
24 int lower=*--s.lower_bound(y);
25 int upper=*s.lower_bound(y);
26 ANS=min(ANS,y-lower),ANS=min(ANS,upper-y);
27 s.insert(y);
28 }
29 int main()
30 {
31 n=read(),m=read();
32 s.insert(-1e9); s.insert(1e9);
33 ANS=2e9;
34 ref(i,1,n)a[i]=b[i]=read(),Insert(a[i]);
35 ref(i,2,n)
36 {
37 int s=abs(a[i]-a[i-1]),tmp=++mp[s];
38 if(tmp==1)q.push(s);
39 }
40 ref(i,1,m)
41 {
42 char st[20];scanf("%s",&st);
43 if(st[0]==‘I‘)
44 {
45 int x=read(),y=read();
46 Insert(y);
47 int s=abs(a[x+1]-b[x]),tmp;--mp[s];
48 s=abs(b[x]-y);tmp=++mp[s];
49 if(tmp==1)q.push(s);
50 s=abs(a[x+1]-y);tmp=++mp[s];
51 if(tmp==1)q.push(s);
52 b[x]=y;
53 }
54 else
55 {
56 if(st[4]==‘G‘)
57 {
58 while(!mp[q.top()])q.pop();
59 printf("%d\n",q.top());
60 }
61 else printf("%d\n",ANS);
62 }
63 }
64 }