# BZOJ2002弹飞绵羊

xiaoxiao2021-03-26  7

LCT做法

研究了一晚上，第二天调出来，过了样例。

一交一个CE。

你猜怎么着？

我交了无数遍C

然后miaomiao大神说了一句：你交的C

我.....

所以以后一定一定一定一定一定一定一定一定一定一定一定一定一定一定一定一定一定一定一定一定一定一定一定一定CE了要记得看看交的啥语言。

代码如下，具体分析各种blog上都有，我也是看了题解的蒟蒻。

#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define For(i, a, b) for(int i = (a); i <= (int)b; i++) #define Forr(i, a, b) for(int i = (a); i >= (int)b; i--) #define Set(a, v) memset(a, v, sizeof(a)) #define LL longlong #define pb puah_back #define N (200000+10) int rt[N], size[N], fa[N], ch[N][2]; void pushup(int x){ size[x] = size[ch[x][0]] + size[ch[x][1]] + 1; } void rotate(int x){ int y = fa[x], key = ch[y][1] == x; ch[y][key] = ch[x][!key]; fa[ch[x][!key]] = y; ch[x][!key] = y; fa[x] = fa[y]; fa[y] = x; if(rt[y]){ rt[y] = 0; rt[x] = 1; } else ch[fa[x]][ch[fa[x]][1]==y]=x; pushup(y); } void splay(int x){ while(!rt[x]){ int y = fa[x], z = fa[y]; if(rt[y]) rotate(x); else{ if((ch[y][1] == x) == (ch[z][1] == y)){ rotate(y); rotate(x); } else{ rotate(x); rotate(x); } } } pushup(x); } void access(int x){ int y = 0; while(x){ splay(x); rt[ch[x][1]] = 1; rt[y] = 0; ch[x][1] = y; pushup(x); y = x, x = fa[x]; } } void mt(int x){ access(x); splay(x); } void link(int x, int y){ mt(x); fa[ch[x][0]] = 0; rt[ch[x][0]] = 1; ch[x][0] = 0; fa[x] = y; pushup(x); } int main(){ int n, m; scanf("%d", &n); For(i, 1, n) rt[i] = 1, size[i] = 1; For(i, 1, n){ int x; scanf("%d", &x); if(i + x <= n) link(i, i+x); } scanf("%d", &m); while(m--){ int T, x, y; scanf("%d", &T); if(T == 1){ scanf("%d", &x); x++; mt(x); printf("%d\n", size[ch[x][0]]+1); } else if(T == 2){ scanf("%d%d", &x, &y); x++; if(x+y > n) link(x, 0); else link(x, x+y); } } return 0; }