//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.9D-query",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#include<cmath>",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=3e4+3,M=2e5+3;",
            "int n,T,BL,ans,A[N],cnt[1000003],Ans[M];",
            "struct Query{",
            "    int l,r,id;",
            "    inline bool operator<(const Query &O)const{",
            "        Re B1=l/BL,B2=O.l/BL;",
            "        return B1!=B2?B1<B2:((B1&1)?r<O.r:r>O.r);",
            "    }",
            "}Q[M];",
            "inline void in(Re &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 void add(Re x){ans+=!cnt[x]++;}",
            "inline void del(Re x){ans-=!--cnt[x];}",
            "int main(){",
            "    in(n),BL=sqrt(n)+1;",
            "    for(Re i=1;i<=n;++i)in(A[i]);",
            "    in(T);",
            "    for(Re i=1;i<=T;++i)in(Q[i].l),in(Q[i].r),Q[i].id=i;",
            "    sort(Q+1,Q+T+1);Re nowL=1,nowR=0;",
            "    for(Re i=1;i<=T;++i){",
            "        while(nowR<Q[i].r)add(A[++nowR]);",
            "        while(nowR>Q[i].r)del(A[nowR--]);",
            "        while(nowL>Q[i].l)add(A[--nowL]);",
            "        while(nowL<Q[i].l)del(A[nowL++]);",
            "        Ans[Q[i].id]=ans;",
            "    }",
            "    for(Re i=1;i<=T;++i)printf(\"%d\\n\",Ans[i]);",
            "}",
            ""
        ],
        "description": "插入 静态莫队"
    }
}