#include<bits/stdc++.h>
using namespace std;
inline int read()
{
int res=0,f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){res=(res<<1)+(res<<3)+(c^48);c=getchar();}
return res*f;
}
void write(int x)
{
if(x<0){putchar('-');x=-x;}
if(x>9)write(x/10);
putchar(x%10+'0');
}
struct node
{
int l,r,siz,rnd,val;
int maxn,sum,lmax,rmax;
int tag_cov,tag_rev;
}t[114514<<1];
int root,cnt;
int New(int x)
{
t[++cnt].siz=1;
t[cnt].sum=t[cnt].val=t[cnt].lmax=t[cnt].rmax=t[cnt].maxn=x;
t[cnt].tag_cov=-114514;
t[cnt].rnd=rand();
return cnt;
}
void update(int p)
{
t[p].siz=t[t[p].l].siz+t[t[p].r].siz+1;
t[p].sum=t[p].val;
t[p].sum+=t[t[p].l].sum+t[t[p].r].sum;
t[p].lmax=t[t[p].l].sum+t[p].val+max(t[t[p].r].lmax,0);
t[p].rmax=t[t[p].r].sum+t[p].val+max(t[t[p].l].rmax,0);
t[p].maxn=t[p].val+max(t[t[p].l].rmax,0)+max(t[t[p].r].lmax,0);
if(t[p].l)
{
t[p].lmax=max(t[t[p].l].lmax,t[p].lmax);
t[p].maxn=max(t[p].maxn,t[t[p].l].maxn);
}
if(t[p].r)
{
t[p].rmax=max(t[t[p].r].rmax,t[p].rmax);
t[p].maxn=max(t[p].maxn,t[t[p].r].maxn);
}
}
void update_p(int p,int x)
{
t[p].lmax=t[p].rmax=t[p].maxn=max(x,x*t[p].siz);
t[p].sum=x*t[p].siz;
t[p].val=x;
}
void down(int p)
{
if(t[p].tag_rev)
{
if(t[p].l)
t[t[p].l].tag_rev^=1;
if(t[p].r)
t[t[p].r].tag_rev^=1;
swap(t[p].l,t[p].r);
swap(t[p].lmax,t[p].rmax);
t[p].tag_rev=0;
}
if(t[p].tag_cov!=-114514)
{
if(t[p].l)
{
t[t[p].l].tag_cov=t[p].tag_cov;
update_p(t[p].l,t[p].tag_cov);
}
if(t[p].r)
{
t[t[p].r].tag_cov=t[p].tag_cov;
update_p(t[p].r,t[p].tag_cov);
}
t[p].tag_cov=-114514;
}
}
void split(int p,int v,int &x,int &y)
{
down(p);
if(!p)
x=y=0;
else
{
if(t[t[p].l].siz+1<=v)
{
x=p;
split(t[p].r,v-t[t[p].l].siz-1,t[p].r,y);
}
else
{
y=p;
split(t[p].l,v,x,t[p].l);
}
update(p);
}
}
int merge(int x,int y)
{
if(!x||!y)
return x|y;
down(x),down(y);
if(t[x].rnd<t[y].rnd)
{
t[x].r=merge(t[x].r,y);
update(x);
return x;
}
else
{
t[y].l=merge(x,t[y].l);
update(y);
return y;
}
}
void insert(int v,int x)
{
int a,b;
split(root,x-1,a,b);
root=merge(a,merge(New(v),b));
}
void del(int x)
{
int a,b,c;
split(root,x,b,c);
split(b,x-1,a,b);
root=merge(a,c);
}
void rev(int l,int r)
{
int a,b,c;
split(root,r,b,c);
split(b,l-1,a,b);
t[b].tag_rev^=1;
merge(a,merge(b,c));
}
void change(int l,int r,int v)
{
int a,b,c;
split(root,r,b,c);
split(b,l-1,a,b);
update_p(b,v);
t[b].tag_cov=v;
merge(a,merge(b,c));
}
int query_sum(int l,int r)
{
int a,b,c;
split(root,r,b,c);
split(b,l-1,a,b);
int res=t[b].sum;
merge(a,merge(b,c));
return res;
}
int query_max(int l,int r)
{
int a,b,c;
split(root,r,b,c);
split(b,l-1,a,b);
int res=t[b].maxn;
merge(a,merge(b,c));
return res;
}
int n,m;
int main()
{
// freopen("P2710_2.in","r",stdin);
// freopen("1.out","w",stdout);
n=read(),m=read();
for(int i=1;i<=n;i++)
{
int x=read();
insert(x,i);
}
while(m--)
{
string op;
cin>>op;
if(op=="INSERT")
{
int x=read();n=read();
for(int i=1;i<=n;i++)
insert(read(),i+x);
}
else if(op=="DELETE")
{
int x=read();n=read();
for(int i=1;i<=n;i++)
del(i+x);
}
else if(op=="REVERSE")
{
int x=read();n=read();
rev(x,x+n-1);
}
else if(op=="MAKE-SAME")
{
int x=read();n=read();int v=read();
change(x,x+n-1,v);
}
else if(op=="GET-SUM")
{
int x=read();n=read();
write(query_sum(x,x+n-1)),puts("");
}
else if(op=="GET")
{
int x=read();
write(query_sum(x,x)),puts("");
}
else
{
int x=read();n=read();
write(query_max(x,x+n-1)),puts("");
}
}
}