# bzoj2002【HNOI2010】Bounce 弹飞绵羊

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

Time Limit: 10 Sec  Memory Limit: 259 MB
Submit: 7467  Solved: 3934
[Submit][Status][Discuss]

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

## Sample Output

2
3

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define F(i,j,n) for(int i=j;i<=n;i++)
#define D(i,j,n) for(int i=j;i>=n;i--)
#define ll long long
#define maxn 200005
using namespace std;
int n,m,block;
int a[maxn],num[maxn],f[maxn],p[maxn];
{
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*10+ch-'0';ch=getchar();}
return x*f;
}
int calc(int x)
{
int ret=0;
for(;x;x=p[x]) ret+=f[x];
return ret;
}
int main()
{
block=round(sqrt(n));
D(i,n,1)
{
if (i+a[i]>n) f[i]=1,p[i]=0;
else if (num[i]==num[i+a[i]]) f[i]=f[i+a[i]]+1,p[i]=p[i+a[i]];
else f[i]=1,p[i]=i+a[i];
}
while (m--)
{
if (opt==1) printf("%d\n",calc(x));
else
{
D(i,x,(num[x]-1)*block+1)
{
if (i+a[i]>n) f[i]=1,p[i]=0;
else if (num[i]==num[i+a[i]]) f[i]=f[i+a[i]]+1,p[i]=p[i+a[i]];
else f[i]=1,p[i]=i+a[i];
}
}
}
return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define F(i,j,n) for(int i=j;i<=n;i++)
#define D(i,j,n) for(int i=j;i>=n;i--)
#define ll long long
#define N 200005
using namespace std;
int n,m,nxt[N],st[N];
struct LCT
{
int ch[N][2],fa[N],sz[N];bool rev[N];
inline bool isroot(int x)
{
return (ch[fa[x]][0]!=x&&ch[fa[x]][1]!=x);
}
inline void pushdown(int x)
{
if (!rev[x]) return;
rev[ch[x][0]]^=1;rev[ch[x][1]]^=1;
swap(ch[x][0],ch[x][1]);
rev[x]=0;
}
inline void pushup(int x)
{
sz[x]=sz[ch[x][0]]+sz[ch[x][1]]+1;
}
void rotate(int x)
{
int y=fa[x],z=fa[y],l=ch[y][1]==x,r=l^1;
if (!isroot(y)) ch[z][ch[z][1]==y]=x;
fa[x]=z;fa[y]=x;fa[ch[x][r]]=y;
ch[y][l]=ch[x][r];ch[x][r]=y;
pushup(y);pushup(x);
}
void splay(int x)
{
int top=0;st[++top]=x;
for(int i=x;!isroot(i);i=fa[i]) st[++top]=fa[i];
D(i,top,1) pushdown(st[i]);
while (!isroot(x))
{
int y=fa[x],z=fa[y];
if (!isroot(y))
{
if (ch[y][0]==x^ch[z][0]==y) rotate(x);
else rotate(y);
}
rotate(x);
}
}
void access(int x)
{
int t=0;
while (x)
{
splay(x);
ch[x][1]=t;
t=x;x=fa[x];
}
}
inline void moveroot(int x)
{
access(x);splay(x);rev[x]^=1;
}
{
moveroot(x);fa[x]=y;
}
inline void cut(int x,int y)
{
moveroot(x);access(y);splay(y);ch[y][0]=fa[x]=0;
}
inline int query(int x)
{
moveroot(n+1);access(x);splay(x);
return sz[ch[x][0]];
}
}lct;
{
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*10+ch-'0';ch=getchar();}
return x*f;
}
int main()
{
F(i,1,n)
{
nxt[i]=lct.fa[i]=min(i+x,n+1);
lct.sz[i]=1;
}
while (m--)
{
if (opt==1) printf("%d\n",lct.query(x));
else
{
}
}
return 0;
}


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

2015-08-10 13:41:57

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

2014-10-21 17:22:10

#### [bzoj2002] [Hnoi2010]Bounce 弹飞绵羊

2016-08-13 21:55:19

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

2016-08-18 19:44:57

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

2015-08-03 22:20:13

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

2017-07-20 08:56:08

#### 【bzoj2002】 [Hnoi2010]Bounce 弹飞绵羊

2015-09-27 13:43:07

#### 【HNOI 2010】弹飞绵羊

2015-09-10 15:18:02

#### Hnoi2010弹飞绵羊题解LCT

2015-08-13 15:40:45

#### 【BZOJ2002】弹飞绵羊（HNOI2010）-LCT模板题

2017-04-23 10:45:09