BZOJ2002弹飞绵羊

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;
} 




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值