Code:
#include<bits/stdc++.h>
#define maxn 600000
#define inf 1000000000
using namespace std;
void setIO(string s)
{
string in=s+".in", out=s+".out";
freopen(in.c_str(),"r",stdin);
// freopen(out.c_str(),"w",stdout);
}
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
multiset<int>S1, S2;
multiset<int>::iterator ita, itb;
vector<int>q[maxn];
char str[maxn];
int Arr[maxn],st[maxn],ed[maxn];
int main()
{
// setIO("input");
int n,m,i,j,a,b, c1,c2, minv=inf;
n=read(),m=read();
for(i=1;i<=n;++i) st[i]=ed[i]=Arr[i]=a=read(), S2.insert(a);
sort(Arr+1,Arr+1+n);
for(i=2;i<=n;++i)
{
minv=min(minv, abs(Arr[i]-Arr[i-1]));
S1.insert(abs(st[i]-st[i-1]));
}
S2.insert(-inf); S2.insert(inf);
st[0]=ed[0]=st[n+1]=ed[n+1]=inf;
while(m--)
{
scanf("%s",str);
if(str[0]=='I')
{
a=read(),b=read();
S1.erase(S1.lower_bound(abs(ed[a] - st[a+1])));
S1.insert(abs(b - ed[a]));
S1.insert(abs(b - st[a+1]));
ed[a]=b;
ita=S2.lower_bound(b);
minv=min(minv, abs((*ita)-b));
ita--;
minv=min(minv, abs((*ita)-b));
S2.insert(b);
}
if(str[4]=='G') printf("%d\n",(*S1.begin()));
if(str[4]=='S')
{
printf("%d\n",minv);
}
}
return 0;
}