//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 的格式要求是 "插入 [该代码片段的中文名]"

{
    "7.区修,单查": {
        "prefix": "acm-2.9+,×",
        "body": [
            "#pragma GCC optimize(3,\"Ofast\",\"inline\")",
            "#pragma GCC optimize(2)",
            "#include<cstdio>",
            "#include<cmath>",
            "#define Re register int",
            "#define F(x,a,b) for(Re x=a;x<=b;++x)",
            "const int N=1e5+3,T=320;",
            "int n,t,x,l,r,Q,fu,P=10007,pt[N],L[T],R[T],a[N],add[T],mul[T];",
            "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();",
            "    x=fu?-x:x;",
            "}",
            "inline void spread(Re p){",
            "\tF(i,L[p],R[p])(((a[i]*=mul[p])%=P)+=add[p])%=P;",
            "\tadd[p]=0,mul[p]=1;",
            "}",
            "inline void change(Re l,Re r,Re x){",
            "\tRe p=pt[l],q=pt[r];spread(p);",
            "\tif(p==q)F(i,l,r)(a[i]+=x)%=P;",
            "\telse{",
            "\t\tspread(q);",
            "\t\tF(i,p+1,q-1)(add[i]+=x)%P;",
            "\t\tF(i,l,R[p])(a[i]+=x)%=P;",
            "\t\tF(i,L[q],r)(a[i]+=x)%=P;",
            "\t}",
            "}",
            "inline void change2(Re l,Re r,Re x){",
            "\tRe p=pt[l],q=pt[r];spread(p);",
            "\tif(p==q)F(i,l,r)(a[i]*=x)%=P;",
            "\telse{",
            "\t\tspread(q);",
            "\t\tF(i,p+1,q-1)(add[i]*=x)%=P,(mul[i]*=x)%=P;",
            "\t\tF(i,l,R[p])(a[i]*=x)%=P;",
            "\t\tF(i,L[q],r)(a[i]*=x)%=P;",
            "\t}",
            "}",
            "inline int ask(Re x){return (a[x]*mul[pt[x]]%P+add[pt[x]])%P;}",
            "int main(){",
            "\tin(n),t=sqrt(Q=n);",
            "\tF(i,1,t)L[i]=(i-1)*t+1,R[i]=i*t,mul[i]=1;",
            "\tif(R[t]<n)R[++t]=n,L[t]=R[t-1]+1,mul[t]=1;",
            "\tF(i,1,n)in(a[i]);",
            "\tF(i,1,t)F(j,L[i],R[i])pt[j]=i;",
            "\twhile(Q--){",
            "\t\tin(n),in(l),in(r),in(x);",
            "\t\tif(n>1)printf(\"%d\\n\",ask(r));",
            "\t\telse n?change2(l,r,x%P):change(l,r,x%P);",
            "\t}",
            "}",
            ""
        ],
        "description": "插入 7.区修,单查"
    }
}