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

{
    "区修，区查(gcd) (Interval GCD)": {
        "prefix": "acm-2.6+",
        "body": [
            "#include<cstdio>",
            "#define LL long long",
            "#define Re register int",
            "const int N=5e5+3;",
            "int n,x,y,T;LL z,A[N];char op;",
            "template<typename T>inline void in(T &x){",
            "    int f=0;x=0;char c=getchar();",
            "    while(c<'0'||c>'9')f|=c=='-',c=getchar();",
            "    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();",
            "    x=f?-x:x;",
            "}",
            "inline LL abs(LL a){return a<0?-a:a;}",
            "inline LL gcd(LL a,LL b){return !b?a:gcd(b,a%b);}",
            "struct BIT{",
            "    LL C[N];",
            "    inline void add(Re x,LL v){while(x<=n)C[x]+=v,x+=x&-x;}",
            "    inline void add(Re L,Re R,LL v){add(L,v),add(R+1,-v);}",
            "    inline LL ask(Re x){LL ans=0;while(x)ans+=C[x],x-=x&-x;return ans;}",
            "}TR0;",
            "struct Segment_Tree{",
            "    #define pl (p<<1)",
            "    #define pr (p<<1|1)",
            "    #define mid ((L+R)>>1)",
            "    LL tr[N<<2];",
            "    inline void pushup(Re p){tr[p]=gcd(tr[pl],tr[pr]);}",
            "    inline void build(Re p,Re L,Re R){",
            "        if(L==R){tr[p]=A[L]-A[L-1];return;}",
            "        build(pl,L,mid),build(pr,mid+1,R);",
            "        pushup(p);",
            "    }",
            "    inline void change(Re p,Re L,Re R,Re x,LL v){",
            "        if(L==R){tr[p]+=v;return;}",
            "        if(x<=mid)change(pl,L,mid,x,v);",
            "        else change(pr,mid+1,R,x,v);",
            "        pushup(p);",
            "    }",
            "    inline LL ask(Re p,Re L,Re R,Re l,Re r){",
            "        if(l<=L&&R<=r)return abs(tr[p]);",
            "        if(r<=mid)return ask(pl,L,mid,l,r);",
            "        else if(l>mid)return ask(pr,mid+1,R,l,r);",
            "        else return gcd(ask(pl,L,mid,l,r),ask(pr,mid+1,R,l,r));",
            "    }",
            "}TR;",
            "int main(){",
            "    in(n),in(T);",
            "    for(Re i=1;i<=n;++i)in(A[i]),TR0.add(i,i,A[i]);",
            "    TR.build(1,1,n);",
            "    while(T--){",
            "        scanf(\" %c\",&op),in(x),in(y);",
            "        if(op=='Q')printf(\"%lld\\n\",gcd(TR0.ask(x),TR.ask(1,1,n,x+1,y)));",
            "        else{",
            "            in(z),TR0.add(x,y,z),TR.change(1,1,n,x,z);if(y<n)TR.change(1,1,n,y+1,-z);",
            "        }",
            "    }",
            "}",
            ""
        ],
        "description": "插入 区修，区查(gcd) (Interval GCD)"
    }
}