//Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and 
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
// same ids are connected.
// prefix 的格式要求是 acm-[一级标题编号].[二级标题编号][该代码片段的英文简称]
// description 的格式要求是 "插入 [该代码片段的中文名]"

{
    "脑洞治疗仪": {
        "prefix": "acm-2.10optimize",
        "body": [
            "#pragma GCC optimize(3,\"Ofast\",\"inline\")",
            "#pragma GCC optimize(2)",
            "#include<algorithm>",
            "#include<cstdio>",
            "#include<vector>",
            "#include<set>",
            "#define Re register int",
            "#define IT set<QAQ>::iterator",
            "using namespace std;",
            "const int N=2e5+5;",
            "struct QAQ{",
            "    int l,r;mutable int v;",
            "    QAQ(Re L,Re R=-1,Re V=0):l(L),r(R),v(V){}",
            "    bool operator<(QAQ o)const{return l<o.l;}",
            "};",
            "int x,y,xx,yy,n,m,fu,op;set<QAQ>s;",
            "inline void in(Re &x){",
            "    x=fu=0;char c=getchar();",
            "    while(c<'0'||c>'9')fu|=c=='-',c=getchar();",
            "    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();",
            "    if(fu)x=-x;",
            "}",
            "inline IT split(Re w){",
            "    IT it=s.lower_bound(QAQ(w));",
            "    if(it!=s.end()&&it->l==w)return it;",
            "    --it;",
            "    Re L=it->l,R=it->r,V=it->v;",
            "    s.erase(it);",
            "    s.insert(QAQ(L,w-1,V));",
            "    return s.insert(QAQ(w,R,V)).first;",
            "}",
            "inline void assign(Re l,Re r,Re v){",
            "    IT itr=split(r+1),itl=split(l);",
            "    s.erase(itl,itr),s.insert(QAQ(l,r,v));",
            "}",
            "inline int ask1(Re l,Re r){",
            "\tIT itr=split(r+1),itl=split(l);Re tmp=0,ans=0;",
            "\twhile(itl!=itr){",
            "\t\tif(!itl->v)tmp+=itl->r-itl->l+1;",
            "\t\telse ans=max(ans,tmp),tmp=0;",
            "\t\t++itl;",
            "\t}",
            "\treturn max(ans,tmp);",
            "}",
            "inline void scure(Re l,Re r,Re a,Re b){",
            "\tIT itr=split(r+1),itl=split(l),it=itl;Re t=0;",
            "\twhile(it!=itr)t+=it->v*(it->r-it->l+1),++it;",
            "\ts.erase(itl,itr),s.insert(QAQ(l,r,0));",
            "\tif(!t)return;",
            "\titr=split(b+1),itl=split(a);",
            "\tif(t>=b-a+1){s.erase(itl,itr),s.insert(QAQ(a,b,1));return;}",
            "\tfor(;itl!=itr;++itl)",
            "\t\tif(!itl->v){",
            "\t\t\tt-=itl->r-itl->l+1;",
            "\t\t\tif(t<0){assign(itl->l,itl->r+t,1);break;}",
            "\t\t\telse itl->v=1;",
            "\t\t}",
            "}",
            "int main(){",
            "    in(n),in(m);",
            "    s.insert(QAQ(1,n,1));",
            "    while(m--){",
            "        in(op),in(x),in(y);",
            "        if(!op)assign(x,y,0);",
            "        else if(op<2)in(xx),in(yy),scure(x,y,xx,yy);",
            "        else printf(\"%d\\n\",ask1(x,y));",
            "    }",
            "}",
            ""
        ],
        "description": "插入 脑洞治疗仪"
    }
}