Language: C

#include<iostream>
#include<stdio.h>
#include<algorithm>
#define lson ch[x][0]
#define rson ch[x][1]
#define rlson ch[ch[root][1]][0]
using namespace std;
//typedef long long LL;
typedef int LL;
const int N=500050;
const int inf=(int)1e8;
int n,m,cas;
struct KEY
{
    LL ls,rs,ms,sum,key,sz;
    KEY(){sz=0;}
    KEY(int val){
        sz=1;
        key=ls=rs=ms=sum=val;
    }
    ///蜿ッ閭ス譌?キヲ蜿ウ蜆ソ蟄撰シ径,b譏ッkey[0],豕ィ諢丞、?炊key[0]逧??
    void print(){
        printf("ls=%d rs=%d ms=%d sum=%d %d\n",ls,rs,ms,sum,key);
    }
    void up(KEY a,KEY b)
    {
        sz=1+a.sz+b.sz;
        sum=key;
        if(a.key!=-inf) sum+=a.sum;
        if(b.key!=-inf) sum+=b.sum;

        if(a.key==-inf) ls=max(key,key+b.ls);
        else ls=max(a.sum+key,a.sum+key+b.ls);
        ls=max(ls,a.ls);

        if(b.key==-inf) rs=max(key,key+a.rs);
        else rs=max(b.sum+key,b.sum+key+a.rs);
        rs=max(rs,b.rs);

        LL tmp=key;
        if(a.rs>0) tmp+=a.rs;
        if(b.ls>0) tmp+=b.ls;
        ms=max(a.ms,b.ms);
        ms=max(ms,tmp);
        if(m==cas)
        {
            puts("---------------------------------");
            print();
            a.print();
            b.print();
        }
    }
    void rev(){
        swap(ls,rs);
    }
    void setc(LL c){
        key=c;
        sum=sz*c;
        ls=rs=ms=max(c,sum);
    }
};
bool flag;
int num[N];
struct SPT
{
    int cnt,root,ch[N][2],pre[N],lazy[N],add[N];
    KEY key[N];
    void push_up(int x){
        if(m==cas)printf("x=%d %d %d\n",x,lson,rson);
        key[x].up(key[lson],key[rson]);
    }
    void push_down(int x){
        if(lazy[x]){
            lazy[lson]^=1;
            lazy[rson]^=1;
            swap(lson,rson);
            key[lson].rev();
            key[rson].rev();
            lazy[x]=0;
        }
        if(add[x]){
            add[lson]=add[x];///豁、螟?弍add陦ィ遉コ菫ョ謾ケ謌芯逧?峩譁ー譁ケ蠑擾シ御ク肴弍蜉?
            add[rson]=add[x];
            key[lson].setc(add[x]);
            key[rson].setc(add[x]);
            add[x]=0;
        }
    }
    void newnode(int &x,int val)
    {
        x=++cnt;
        key[x]=KEY(val);
        pre[x]=lson=rson=0;
        lazy[x]=add[x]=0;
    }
    void rotate(int x,int kind)
    {
        int y=pre[x];
        push_down(y);
        push_down(x);
        if(pre[y]) ch[pre[y]][ ch[pre[y]][1]==y ]=x;
        pre[x]=pre[y];

        ch[y][!kind]=ch[x][kind];
        if(ch[x][kind]) pre[ch[x][kind]]=y;

        pre[y]=x;
        ch[x][kind]=y;
        push_up(y);
//        if(x==pre[x]||y==pre[y]) while(1);
    }
    void splay(int x,int goal)
    {
        if(x==0) return ;
//        cout<<"x="<<x<<' '<<pre[x]<<endl;
        push_down(x);
        while(pre[x]!=goal)
        {
            int y=pre[x];
            if(pre[y]==goal)
                rotate(x,ch[y][1]!=x);//puts("11111");
            else{
//                puts("2222222");
                int kind=(ch[pre[y]][1]==y);
                if(ch[y][kind]==x)
                    rotate(y,!kind),rotate(x,!kind);
                else
                    rotate(x,kind),rotate(x,!kind);
            }
//            cout<<"x="<<x<<' '<<pre[x]<<endl;
        }
        push_up(x);
        if(goal==0) root=x;
    }
    void roto(int k,int goal){
        int x=root;
        push_down(x);
        while(key[lson].sz!=k){
            if(k<key[lson].sz)
                x=lson;
            else{
                k-=(1+key[lson].sz);
                x=rson;
            }
            push_down(x);
        }
//        puts("roto");
//        printf("x=%d %d\n",x,goal);
        splay(x,goal);
    }

    void init()
    {
        cnt=root=0;
        key[0].sz=0;
        key[0].key=key[0].ls=key[0].rs=key[0].ms=-inf;
        key[0].sum=-inf;
        newnode(root,-1);
        newnode(ch[root][1],-1);
        pre[ch[root][1]]=root;
        push_up(root);
    }
    void build(int l,int r,int &x,int f){
        if(l>r) return ;
        int mid=l+r>>1;
        newnode(x,num[mid]);
        pre[x]=f;
        build(l,mid-1,ch[x][0],x);
        build(mid+1,r,ch[x][1],x);
//        printf("%d %d %d %d\n",x,ch[x][0],ch[x][1],key[x].key);
        push_up(x);
    }
    ///蝨ィpos荳ェ謨ー蜷主刈蜈・tot荳ェ謨ー
    ///豕ィ諢乗薯蜈・逧дot荳ェ謨ー蠢?。サ蜈郁ッサ蜈・蛻ーnum[1...tot]
    void insert(int pos,int tot)
    {
        roto(pos,0);
        roto(pos+1,root);
        build(1,tot,rlson,ch[root][1]);
        push_up(ch[root][1]);
        push_up(root);
    }
    void remove(int a,int tot)
    {
//        cout<<a<<" hhh "<<a+tot+1<<endl;
        roto(a-1,0);
        roto(a+tot,root);
        int x=rlson;
        rlson=0;
        push_up(ch[root][1]);
        push_up(root);
    }
    void setc(int a,int tot,int c)
    {
//        cout<<a<<' '<<a+tot+1<<endl;
        roto(a-1,0);
        roto(a+tot,root);
//        print();
//        cout<<key[rlson].key<<endl;
        add[rlson]=c;
        key[rlson].setc(c);
//        cout<<key[rlson].key<<endl;
        push_up(ch[root][1]);
        push_up(root);
    }
    void rev(int a,int tot){
        roto(a-1,0);
        roto(a+tot,root);
        key[rlson].rev();
        lazy[rlson]^=1;
        push_up(ch[root][1]);
        push_up(root);
    }
    int getsum(int a,int b){
//        puts("hh");
        roto(a-1,0);
//        splay(5,0);
//        puts("hhhh");
//        printf("%d %d\n",a,b);
        roto(b+1,root);
//        print();
//        printf("%d %d\n",key[root].sz,key[rlson].sz);
//        printf("%d %d\n",a-1,b+1);
//        return rlson;
        return key[rlson].sum;
    }
    int getmx(int a,int b)
    {
//        roto(a-1,0);
//        roto(b+1,root);
        roto(0,0);
        roto(key[root].sz-1,root);
        return key[rlson].ms;
    }
    void print()
    {
        roto(0,0);
        roto(key[root].sz-1,root);
        flag=0;
        travel(rlson);
        puts("");
    }
    void travel(int x)
    {
        if(x==0) return ;
//        if(m==cas)printf("%d %d %d %d\n",x,ch[x][0],ch[x][1],key[x].key);
        push_down(x);
        travel(ch[x][0]);
//        if(flag) putchar(' ');
//        flag=1;
//        printf("%d",key[x].key);
//        printf("%d %d %d mx=%d\n",x,pre[x],key[x].key,key[x].ms);
        travel(ch[x][1]);
    }

}spt;
int main()
{
    cas=3;
//    cas=10;
    freopen("1.in","r",stdin);
    while(scanf("%d%d",&n,&m)!=-1&&n>=0)
    {
        for(int i=1;i<=n;++i)
            scanf("%d",&num[i]);
        spt.init();
        spt.insert(0,n);
//        return 0;

//        puts("hhhh");
//        spt.print();
//        puts("hhhhhhhhh");
        while(m--)
        {
            char s[20];
            int a,b,c;
            if(m==cas) puts("**********************");
            if(m==3)
            spt.print();
            scanf("%s",s);
            if(s[0]=='M'&&s[2]=='X') printf("%d\n",spt.getmx(-1,-1));
            else{
                scanf("%d%d",&a,&b);
                if(s[0]=='G'){
                    printf("%d\n",spt.getsum(a,a+b-1));
                }
                else if(s[0]=='D'){
                    spt.remove(a,b);
                }
                else if(s[0]=='M'){
                    scanf("%d",&c);
                    spt.setc(a,b,c);
                }
                else if(s[0]=='R')
                    spt.rev(a,b);
                else if(s[0]=='I'){
                    for(int i=1;i<=b;++i)
                        scanf("%d",&num[i]);
                    spt.insert(a,b);
                }
                else while(1);
            }
//            scanf("%d%d",&a,&b);
//            spt.rev(a,b);
//            spt.remove(a,b);
//            printf("mx=%d\n",spt.getmx(-1,-1));
//            spt.print();
            if(m==cas) puts("***************************");
        }
        return 0;
    }
    return 0;
}

Compiler output:
main.c:1:9: fatal error: iostream: No such file or directory
    1 | #include<iostream>
      |         ^~~~~~~~~~
compilation terminated.