## 加载中...

----------请检查你的网络设置

# bzoj 2002: [Hnoi2010]Bounce 弹飞绵羊（分块）

## 2002: [Hnoi2010]Bounce 弹飞绵羊

Time Limit: 10 Sec  Memory Limit: 259 MB
Submit: 10761  Solved: 5542
[Submit][Status][Discuss]

4
1 2 1 1
3
1 1
2 1 1
1 1

## Sample Output

2
3

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int a[200005], t[200005], net[200005], bel[200005];
int main(void)
{
int n, m, i, q, len, x, c, ans, k, L, R, p;
while(scanf("%d", &n)!=EOF)
{
for(i=1;i<=n;i++)
scanf("%d", &a[i]);
m = sqrt(1.0*n);
len = n/m;
for(i=n;i>=1;i--)
{
bel[i] = min((i-1)/len+1, m);
x = i+a[i];
if(x>n || bel[x]!=bel[i])
t[i] = 1, net[i] = x;
else
t[i] = t[x]+1, net[i] = net[x];
}
scanf("%d", &q);
while(q--)
{
scanf("%d", &c);
if(c==1)
{
ans = 0;
scanf("%d", &x);
x++;
while(x<=n)
{
ans += t[x];
x = net[x];
}
printf("%d\n", ans);
}
else
{
scanf("%d%d", &x, &k);
x++;
L = (bel[x]-1)*len+1;
R = bel[x]*len;
if(bel[x]==m)  R = n;
for(i=R;i>=L;i--)
{
if(x==i)
a[i] = k;
p = i+a[i];
if(p>n || bel[p]!=bel[i])
t[i] = 1, net[i] = p;
else
t[i] = t[p]+1, net[i] = net[p];
}
}
}
}
return 0;
}

#### BZOJ 2002 [Hnoi2010]Bounce 弹飞绵羊 LCT

2015-08-10 13:41:57

#### BZOJ 2002 HNOI2010 弹飞绵羊 分块

2014-10-21 17:22:10

#### [BZOJ2002][HNOI2010]弹飞绵羊（LCT）

2016-03-27 14:38:13

#### bzoj-2002 Bounce 弹飞绵羊

2015-08-15 16:38:12

#### 动态树-LCT-bzoj2002弹飞绵羊

2016-08-18 19:44:57

#### BZOJ 2002 Bounce 弹飞绵羊(分块|暴力|)(困难)

2015-08-03 22:20:13

#### 洛谷P3203/bzoj2002 [Hnoi2010]Bounce 弹飞绵羊

2017-08-21 16:53:27

#### BZOJ2002: [Hnoi2010]Bounce 弹飞绵羊（洛谷P3203）

2018-01-07 21:11:26

#### 2002: [Hnoi2010]Bounce 弹飞绵羊（分块）

2015-09-21 10:39:27

#### BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊

2014-09-08 22:21:53