没写完,没调完,咕咕咕的代码

本文详细解析了BZOJ平台上的首都题目,使用了高级的数据结构和算法,如链表翻转、倍增查找等,通过具体代码展示了如何解决复杂的数据处理和查询问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

没写完,没调完,咕咕咕的代码

1. bzoj 首都

#include<bits/stdc++.h>
#define maxn 200000
using namespace std;
void setIO(string s)
{
	string in=s+".in",out=s+".out"; 
	freopen(in.c_str(),"r",stdin);  
}
int n,Q,X=0; 
int siz[maxn],son[maxn],root[maxn];   
char str[20];   
namespace tr
{
	#define isrt(x) (!(ch[f[x]][0]==x||ch[f[x]][1]==x)) 
	#define get(x) (ch[f[x]][1]==x) 
	#define lson ch[x][0]
	#define rson ch[x][1] 
	int ch[maxn][2],f[maxn],rev[maxn],sta[maxn]; 
	int findrt(int x)
	{
		while(lson) x=lson;
		return x; 
	}
	void mark(int x)
	{
		if(!x)return; 
		swap(lson,rson), rev[x]^=1; 
	}
	void pushup(int x)
	{
		if(!x)return;    
		siz[x]=siz[lson]+siz[rson]+son[x]+1; 
	}
	void rotate(int x)
	{
		int old=f[x],fold=f[old],which=get(x); 
		if(!isrt(old)) ch[fold][ch[fold][1]==old]=x; 
		ch[old][which]=ch[x][which^1],f[ch[old][which]]=old; 
		ch[x][which^1]=old,f[old]=x,f[x]=fold; 
		pushup(old),pushup(x); 
	}
	void pushdown(int x)
	{
		if(!rev[x]||!x)return; 
		mark(lson), mark(rson),rev[x]^=1; 
	} 
	void splay(int x)
	{
		int v=0,u=x,fa; 
		sta[++v]=u; 
		while(!isrt(u)) sta[++v]=f[u],u=f[u]; 
		while(v) pushdown(sta[v--]); 
		for(u=f[u];(fa=f[x])!=u;rotate(x)) 
			if(f[fa]!=u) 
				rotate(get(x)==get(fa)?fa:x);                    
	}
	void Access(int x)
	{
		int t=0;
		while(x)
		{
			splay(x); 
			son[x]=son[x]+siz[rson]-siz[t]; 
			pushup(x); 
			t=x,x=f[x];               
		}
	}
	void MakeRoot(int x)
	{
		Access(x), splay(x), mark(x); 
	}
	void link(int x,int y)
	{
		MakeRoot(x),f[x]=y,son[y]+=siz[x], pushup(y); 
	}
	void split(int x,int y)
	{
		MakeRoot(x),Access(y),splay(y); 
	}
	int query(int x)
	{
		
	}
}; 
int main()
{
	setIO("input");  
	scanf("%d%d",&n,&Q);    
	for(int i=1;i<=n;++i) root[i]=i; 
	int x,y,a,b,c,d;  
	while(Q--)
	{
		scanf("%s",str);
		switch(str[0]) 
		{
			case 'A' : 
			{       
				scanf("%d%d",&x,&y); 
				a=tr::findrt(x); 
				b=tr::findrt(y);         
				tr::link(x,y); 
				tr::split(a,b);          // b is on top of a 
				tr::query(b);     
			    break; 				
			}
			case 'Q' : 
			{
				scanf("%d",&x); 
				break; 
			}
			case 'X' : 
			{
				printf("%d\n",X);     
				break; 
			}
		} 
	}
	return 0; 
}

  

2. 

posted @ 2019-06-15 17:12 EM-LGH 阅读( ...) 评论( ...) 编辑 收藏
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值