2002: [Hnoi2010]Bounce 弹飞绵羊

Time Limit: 10 Sec  Memory Limit: 259 MB
Submit: 9071  Solved: 4652
[Submit][Status][Discuss]

Description

某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏。游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装置设定初始弹力系数ki,当绵羊达到第i个装置时,它会往后弹ki步,达到第i+ki个装置,若不存在第i+ki个装置,则绵羊被弹飞。绵羊想知道当它从第i个装置起步时,被弹几次后会被弹飞。为了使得游戏更有趣,Lostmonkey可以修改某个弹力装置的弹力系数,任何时候弹力系数均为正整数。

Input

第一行包含一个整数n,表示地上有n个装置,装置的编号从0到n-1,接下来一行有n个正整数,依次为那n个装置的初始弹力系数。第三行有一个正整数m,接下来m行每行至少有两个数i、j,若i=1,你要输出从j出发被弹几次后被弹飞,若i=2则还会再输入一个正整数k,表示第j个弹力装置的系数被修改成k。对于20%的数据n,m<=10000,对于100%的数据n<=200000,m<=100000

Output

对于每个i=1的情况,你都要输出一个需要的步数,占一行。

Sample Input

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

Sample Output

2
3

HINT

 

Source

 

[Submit][Status][Discuss]

将跳转看成边的关系,易知这些转移边形成一棵树。如果以“弹出去”这个状态为根节点,从一个点出发的步数可以转换为深度,或者说是从根节点到这个点的距离。改变一个点的系数,可以视为改变一个点的父节点,但是其子树不会受到影响。显然是个LCT模板题,第一次写还有些许不懂,大体是从这位前辈的blog里学的。

 VAR
n : longint;
m : longint;
siz : array[-..] of longint;
fat : array[-..] of longint;
rot : array[-..] of boolean;
son : array[-..,..] of longint; PROCEDURE update(t : longint);
begin
siz[t]:=siz[son[t,]]+siz[son[t,]]+;
end; PROCEDURE ltrotate(x : longint);
var
y : longint;
begin
y:=son[x,];
son[x,]:=son[y,];
fat[son[x,]]:=x;
son[y,]:=x;
if x=son[fat[x],] then
son[fat[x],]:=y
else if x=son[fat[x],] then
son[fat[x],]:=y;
fat[y]:=fat[x];
fat[x]:=y;
rot[y]:=rot[x] xor rot[y];
rot[x]:=rot[x] xor rot[y];
update(x);
update(y);
end; PROCEDURE rtrotate(x : longint);
var
y : longint;
begin
y:=son[x,];
son[x,]:=son[y,];
fat[son[x,]]:=x;
son[y,]:=x;
if x=son[fat[x],] then
son[fat[x],]:=y
else if x=son[fat[x],] then
son[fat[x],]:=y;
fat[y]:=fat[x];
fat[x]:=y;
rot[y]:=rot[x] xor rot[y];
rot[x]:=rot[x] xor rot[y];
update(x);
update(y);
end; PROCEDURE splay(x : longint);
begin
while not rot[x] do
if x=son[fat[x],] then
ltrotate(fat[x])
else
rtrotate(fat[x]);
end; PROCEDURE access(x : longint);
var
y : longint;
begin
splay(x);
while fat[x]<> do
begin
y:=fat[x];
splay(y);
rot[son[y,]]:=true;
rot[x]:=false;
son[y,]:=x;
update(y);
splay(x);
end;
end; PROCEDURE main;
var
i, x, y, z : longint;
begin
read(n); for i:= to n do
begin
read(fat[i]);
fat[i]:=fat[i]+i;
if fat[i]>n then
fat[i]:=n+;
end; for i:= to n+ do
begin
siz[i]:=;
rot[i]:=true;
end; read(m); for i:= to m do
begin
read(x);
if x= then
begin
read(y);
inc(y);
access(y);
writeln(siz[son[y,]]);
end
else
begin
read(y,z);
inc(y);
splay(y);
fat[son[y,]]:=fat[y];
rot[son[y,]]:=true;
son[y,]:=;
siz[y]:=siz[son[y,]]+;
fat[y]:=y+z;
if fat[y]>n then
fat[y]:=n+;
end;
end;
end; BEGIN
main;
END.
 #include <bits/stdc++.h>

 #define fread_siz 1024

 inline int get_c(void)
{
static char buf[fread_siz];
static char *head = buf + fread_siz;
static char *tail = buf + fread_siz; if (head == tail)
fread(head = buf, , fread_siz, stdin); return *head++;
} inline int get_i(void)
{
register int ret = ;
register int neg = false;
register int bit = get_c(); for (; bit < ; bit = get_c())
if (bit == '-')neg ^= true; for (; bit > ; bit = get_c())
ret = ret * + bit - ; return neg ? -ret : ret;
} template <class T>
inline T min(T a, T b)
{
return a < b ? a : b;
} const int N = ; int n, m;
int root[N];
int lson[N];
int rson[N];
int size[N];
int father[N]; inline void update(int t)
{
size[t] = size[lson[t]] + size[rson[t]] + ;
} inline void rotateLeft(int t)
{
int r = rson[t];
rson[t] = lson[r];
father[rson[t]] = t;
lson[r] = t;
if (t == lson[father[t]])
lson[father[t]] = r;
else if (t == rson[father[t]])
rson[father[t]] = r;
father[r] = father[t];
father[t] = r;
update(t);
update(r);
root[r] ^= root[t];
root[t] ^= root[r];
} inline void rotateRight(int t)
{
int l = lson[t];
lson[t] = rson[l];
father[lson[t]] = t;
rson[l] = t;
if (t == lson[father[t]])
lson[father[t]] = l;
else if (t == rson[father[t]])
rson[father[t]] = l;
father[l] = father[t];
father[t] = l;
update(t);
update(l);
root[l] ^= root[t];
root[t] ^= root[l];
} inline void splay(int t)
{
while (!root[t])
{
if (t == lson[father[t]])
rotateRight(father[t]);
else
rotateLeft(father[t]);
}
} inline void access(int t)
{
splay(t); while (father[t])
{
int f = father[t];
splay(f);
root[rson[f]] = ;
root[t] = ;
rson[f] = t;
update(f);
splay(t);
}
} inline void cut(int t)
{
splay(t);
root[lson[t]] = ;
father[lson[t]] = father[t];
lson[t] = ;
update(t);
} signed main(void)
{
n = get_i(); for (int i = ; i <= n; ++i)
father[i] = min(get_i() + i, n + ); for (int i = ; i <= n + ; ++i)
size[i] = root[i] = ; m = get_i(); for (int i = ; i <= m; ++i)
{
int x = get_i(), y, z;
if (x == )
{
y = get_i() + ; access(y);
printf("%d\n", size[lson[y]]);
}
else
{
y = get_i() + ; z = get_i();
cut(y); father[y] = min(n + , y + z);
}
}
}

@Author: YouSiki

BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊的更多相关文章

  1. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 分块

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOn ...

  2. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 LCT

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOn ...

  3. bzoj 2002: [Hnoi2010]Bounce 弹飞绵羊 動態樹

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 4055  Solved: 2172[Submi ...

  4. bzoj 2002 : [Hnoi2010]Bounce 弹飞绵羊 (LCT)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2002 题面: 2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: ...

  5. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 (动态树LCT)

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 2843  Solved: 1519[Submi ...

  6. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 【分块】

    任意门:https://www.lydsy.com/JudgeOnline/problem.php?id=2002 2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 ...

  7. BZOJ 2002 [Hnoi2010]Bounce 弹飞绵羊:分块

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2002 题意: 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆 ...

  8. 【刷题】BZOJ 2002 [Hnoi2010]Bounce 弹飞绵羊

    Description 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装置 ...

  9. 洛谷 P3203 BZOJ 2002 [Hnoi2010]Bounce 弹飞绵羊

    题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装置设定初始弹力系 ...

随机推荐

  1. 在Thinkphp中使用AJAX实现无刷新分页

    在Thinkphp目录的Lib\ORG\Util\目录里新建AjaxPage.class.php,写入一下内容: <?php // +------------------------------ ...

  2. 浅谈Hybrid技术的设计与实现第三弹——落地篇

    前言 接上文:(阅读本文前,建议阅读前两篇文章先) 浅谈Hybrid技术的设计与实现 浅谈Hybrid技术的设计与实现第二弹 根据之前的介绍,大家对前端与Native的交互应该有一些简单的认识了,很多 ...

  3. Bootstrap 之 Carousel

    Bootstrap 轮播(Carousel)插件是一种灵活的响应式的向站点添加滑块的方式.除此之外,内容也是足够灵活的,可以是图像.内嵌框架.视频或者其他您想要放置的任何类型的内容. 如果您想要单独引 ...

  4. Hadoop学习日志- install hadoop

    资料来源 : http://www.tutorialspoint.com/hadoop/hadoop_enviornment_setup.htm Hadoop 安装 创建新用户 $ su passwo ...

  5. 非域客户端的office使用RMS加密服务出现‘介绍“信息权限管理服务”’服务的提示

    环境:office2007,需要使用windows RMS服务,客户机处于工作组模式,如图: 出现这个说明客户机没有发现RMS服务,可以通过导入注册表解决,如下: Windows Registry E ...

  6. iOS之UI组件整理

    作者:神兽gcc 授权本站转载. 最近把iOS里的UI组件重新整理了一遍,简单来看一下常用的组件以及它们的实现.其实现在这些组件都可以通过Storyboard很快的生成,只是要向这些组件能够变得生动起 ...

  7. 提交本地项目到github服务器

    已经完成的本地项目 提交到github 并不是按照先在github上创建一个仓库 然后clone下来的顺序 1.在github上创建仓库 2.在本地项目初始化git仓库 $ git init 3.添加 ...

  8. [转]ThoughtWorks(中国)程序员读书雷达

    http://agiledon.github.io/blog/2013/04/17/thoughtworks-developer-reading-radar/#rd?sukey=f64bfa68330 ...

  9. 跳转时候提示Attempt to present on while a presentation is in progress

    出现这种情况,例如:我在获取相册图片后,直接present到另一个页面,但是上一个页面可能还未dismiss,所以,要在获取相册图片的dismiss方法的complete的block里面写获取图片及跳 ...

  10. IOS 杂笔-15(知识小点 readonly)

    readonly是我们并不陌生的属性. 但是他也有值得我们注意的地. 属性如其名-只读-也就是说我们只能读取-不能进行写操作 当我们尝试进行写操作时会如下 但是这并不意味着我们不可以改变其内部的属性 ...