# [算法模版]莫队

int cmp(query a, query b) {
return belong[a.l] == belong[b.l] ? a.r < b.r : belong[a.l] < belong[b.l];
}


int cmp(query a, query b) {
return (belong[a.l] ^ belong[b.l]) ? belong[a.l] < belong[b.l] : ((belong[a.l] & 1) ? a.r < b.r : a.r > b.r);
}


[SDOI2009]HH的项链

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define maxn 500500
using namespace std;
int block[maxn],val[maxn],n,m,cnt[1020000],tot,ans[maxn];
struct gg {
int l,r,id;
}q[500500];
if(!cnt[col])tot++;
cnt[col]++;
}
inline void del(int col) {
if(cnt[col]==1)tot--;
cnt[col]--;
}
inline bool cop(gg x,gg y){return (block[x.l]^block[y.l])?x.l<y.l:((block[x.l]&1)?(x.r<y.r):(x.r>y.r));}
int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++){scanf("%d",&val[i]);}
scanf("%d",&m);
int bl=n/sqrt(m*2/3);
for(int i=1;i<=n;i++){block[i]=(i-1)/bl+1;}
for(int i=1;i<=m;i++){scanf("%d%d",&q[i].l,&q[i].r);q[i].id=i;}
sort(q+1,q+1+m,cop);
int l=1,r=1;cnt[val[1]]++;tot=1;
for(int i=1;i<=m;i++) {
int tl=q[i].l,tr=q[i].r;