传送门

分析

基本的lct操作,建一个点N表示弹飞出去的点,每次输出N的左子树的大小即可

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define N n+1
#define rep for(int y=0;x;y=x,x=fa[x])
int a[],son[][],siz[],r[],fa[],x[];
inline void up(int x){siz[x]=siz[son[x][]]+siz[son[x][]]+;}
inline void rev(int x){swap(son[x][],son[x][]);r[x]^=;}
inline void pd(int x){
if(r[x]){
if(son[x][])rev(son[x][]);
if(son[x][])rev(son[x][]);
r[x]=;
}
}
inline bool notroot(int x){return son[fa[x]][]==x||son[fa[x]][]==x;}
inline void push_all(int x){if(notroot(x))push_all(fa[x]);pd(x);}
inline int gs(int x){return son[fa[x]][]==x;}
inline void rot(int x){
int y=fa[x],z=fa[y],b=gs(x),c=gs(y),d=son[x][!b];
if(notroot(y))son[z][c]=x;fa[x]=z;if(d)fa[d]=y;
son[y][b]=d;fa[y]=x;son[x][!b]=y;up(y),up(x);
}
inline void splay(int x){
push_all(x);
while(notroot(x)){
int y=fa[x],z=fa[y];
if(notroot(y)){
if(gs(x)==gs(y))rot(y);
else rot(x);
}
rot(x);
}
}
inline void access(int x){rep splay(x),son[x][]=y,up(x);}
inline void makeroot(int x){access(x);splay(x);rev(x);}
inline void spt(int x,int y){makeroot(x);access(y);splay(y);}
inline void link(int x,int y){makeroot(x);fa[x]=y;}
inline void cut(int x,int y){
makeroot(x);access(y);splay(y);
fa[x]=son[y][]=;
up(y);
}
int main(){
int n,m,i,j,k,t;
scanf("%d",&n);
for(i=;i<=n;i++)siz[i]=;
for(i=;i<=n;i++){
scanf("%d",&x[i]);
if(i+x[i]<=n)link(i,i+x[i]);
else link(i,N);
}
scanf("%d",&m);
for(i=;i<=m;i++){
scanf("%d%d",&k,&t);t++;
if(k==)spt(t,N),printf("%d\n",siz[son[N][]]);
else cut(t,min(N,t+x[t])),scanf("%d",&x[t]),link(t,min(N,t+x[t]));
}
return ;
}

最新文章

  1. Hadoop2.6.0安装 — 集群
  2. JS控制按钮不能连续被点击
  3. sqlserver安装出现问题
  4. C# 使用 Abot 实现 爬虫 抓取网页信息 源码下载
  5. maven问题-&quot;resolution will not be reattempted until the update interval of MyRepo has elapsed&quot;
  6. HDU 5044 (树链剖分+树状数组+点/边改查)
  7. Shell | grep with n following lines
  8. Js Pattern - Self Define Function
  9. 如何利用SecureCRT连接Ubuntu12.0.4
  10. 离开ACM了,总结一下
  11. .10-Vue源码之Watcher(1)
  12. JPA核心类与使用
  13. MySQL外键约束_ON DELETE CASCADE/ON UPDATE CASCADE
  14. 【机器学习】逻辑回归(Logistic Regression)
  15. DMA驱动框架
  16. haproxy acl访问限制IP
  17. LintCode: Fizz Buzz
  18. 工作总结 [all]
  19. BZOJ 4602: [Sdoi2016]齿轮 dfs
  20. iOS常用动画 类封装

热门文章

  1. Project://CRM
  2. LeetCode Minimum Index Sum of Two Lists
  3. 【LeetCode】006. ZigZag Conversion
  4. VS中添加自定义代码片段
  5. 【转】浅谈Java中的equals和==
  6. Python函数-compile()
  7. [转]理解$watch ,$apply 和 $digest --- 理解数据绑定过程
  8. Linux开放80、8080端口或者开放某个端口
  9. linux下常用的基本设置与操作C语言实现
  10. Linux驱动 - 多线程