# [bzoj 4939][Ynoi 2016]掉进兔子洞

## Code

#include<bits/stdc++.h>
#define min(a,b) ((a)<(b)?(a):(b))
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return x*f;
}

#define MN 100005
int n,m,a[MN],T,nums[MN];
std::bitset<MN> now;
std::bitset<MN> quer[33343];
struct ques{
int l,r,id,pl;
bool operator <(const ques&o)const{return (pl^o.pl)?(pl<o.pl):((pl&1)?r<o.r:r>o.r);}
}q[MN+33343];
int num[MN],len[MN];

inline void solve(int L,int R)
{
if(L>R) return;
register int tt=0,i;
for(i=1;i<=R-L+1;++i)
{
quer[i].set();
}
std::sort(q+1,q+tt+1);
register int l=1,r=0;now.reset();
memset(num,0,sizeof num);

for(i=1;i<=tt;++i)
{
for(;r<q[i].r;++r) num[a[r+1]]++,now[a[r+1]+num[a[r+1]]-1]=1;
for(;l>q[i].l;--l) num[a[l-1]]++,now[a[l-1]+num[a[l-1]]-1]=1;
for(;r>q[i].r;--r) now[a[r]+num[a[r]]-1]=0,--num[a[r]];
for(;l<q[i].l;++l) now[a[l]+num[a[l]]-1]=0,--num[a[l]];
quer[q[i].id]&=now;
}
for(i=1;i<=R-L+1;++i) printf("%d\n",len[i]-3*quer[i].count());
}

int main()
{
register int i;T=ceil(sqrt((double)n));