比赛 |
清华集训2017模板练习 |
评测结果 |
AAAAAAAAAA |
题目名称 |
弹飞绵羊 |
最终得分 |
100 |
用户昵称 |
FoolMike |
运行时间 |
1.143 s |
代码语言 |
C++ |
内存使用 |
4.13 MiB |
提交时间 |
2017-12-02 20:23:03 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int n,m,a[N],fa[N],son[N][2],size[N];
#define lc son[x][0]
#define rc son[x][1]
void up(int x){
size[x]=size[lc]+1+size[rc];
}
void rot(int x){
int y=fa[x],z=fa[y];
bool b=(x==son[y][1]);
fa[son[y][b]=son[x][!b]]=y;
fa[son[x][!b]=y]=x;
fa[x]=z;
if (son[z][0]==y) son[z][0]=x;else
if (son[z][1]==y) son[z][1]=x;
up(y);up(x);
}
bool isroot(int x){
return son[fa[x]][0]!=x&&son[fa[x]][1]!=x;
}
void splay(int x){
for (;!isroot(x);rot(x)){
int y=fa[x],z=fa[y];
if (!isroot(y)) rot((x==son[y][0])==(y==son[z][0])?y:x);
}
}
void access(int x){
for (splay(x),rc=0,up(x);fa[x];){
int y=fa[x];
splay(y);
son[y][1]=x;
up(y);
splay(x);
}
}
int main()
{
freopen("bzoj_2002.in","r",stdin);
freopen("bzoj_2002.out","w",stdout);
scanf("%d",&n);
for (int i=1;i<=n;i++){
scanf("%d",&a[i]);
fa[i]=i+a[i];
if (fa[i]>n) fa[i]=0;
size[i]=1;
}
scanf("%d",&m);
for (int i=1;i<=m;i++){
int tp,x,y;
scanf("%d%d",&tp,&x);x++;
if (tp==1){
access(x);
printf("%d\n",size[x]);
}
else{
scanf("%d",&y);
if (x+a[x]<=n) access(x+a[x]);
splay(x);
a[x]=y;
fa[x]=x+a[x];
if (fa[x]>n) fa[x]=0;
}
}
return 0;
}