# Bzoj2002 [hnoi2010]bounce 弹飞绵羊

## 毒瘤分块++

Posted by yjjr's blog on February 4, 2018

Description

1 2 1 1

3

1 1

2 1 1

1 1

Sample Output 2

3

hzwer分块的做法秒啊

# code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(register int i=a;i<=b;i++)
#define dep(i,a,b) for(register int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
using namespace std;
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int maxn=2e5+6;
int pt[maxn],st[maxn],a[maxn],belong[maxn],l[506],r[506];
int n,m,tnum,cnt;
inline int query(int x){
int t=st[x];
while(pt[x])x=pt[x],t+=st[x];
return t;
}
int main(){
if(n%tnum)cnt=n/tnum+1;else cnt=n/tnum;
rep(i,1,cnt)l[i]=(i-1)*tnum+1,r[i]=i*tnum;r[cnt]=n;
rep(i,1,n)belong[i]=(i-1)/tnum+1;
dep(i,n,1){
if(i+a[i]>n)st[i]=1;
else if(belong[i]==belong[i+a[i]])st[i]=st[i+a[i]]+1,pt[i]=pt[i+a[i]];
else st[i]=1,pt[i]=i+a[i];
}
rep(i,1,m){