[BZOJ2843][LCT]极地旅行社
来源:互联网 发布:将压缩的js还原 编辑:程序博客网 时间:2024/04/27 20:24
LCT裸题
#include <cstdio>#include <algorithm>#include <iostream>#define N 30010using namespace std;int n,m,tp,x,y;int A[N],fa[N],ch[N][2],v[N],rev[N],sta[N];char op[10];inline int isl(int x){return ch[fa[x]][1]==x;}inline int isr(int x){return ch[fa[x]][0]!=x&&ch[fa[x]][1]!=x;}inline void pushdown(int x){ if(!(x&&rev[x])) return; swap(ch[x][0],ch[x][1]); if(ch[x][0]) rev[ch[x][0]]^=1; if(ch[x][1]) rev[ch[x][1]]^=1; rev[x]=0;}inline void upd(int x){ if(!x) return; v[x]=A[x]; if(ch[x][0]) v[x]+=v[ch[x][0]]; if(ch[x][1]) v[x]+=v[ch[x][1]];}inline void rot(int x){ int y=fa[x],z=fa[y],lor=isl(x); if(!isr(y)) ch[z][ch[z][1]==y]=x; fa[x]=z; if(ch[y][lor]=ch[x][lor^1]) fa[ch[y][lor]]=y; fa[ch[x][lor^1]=y]=x; upd(y); upd(x);}inline void splay(int x){ sta[tp=1]=x; for(int i=x;!isr(i);i=fa[i]) sta[++tp]=fa[i]; for(;tp;--tp) pushdown(sta[tp]); for(;!isr(x);rot(x)) if(!isr(fa[x])) rot(isl(x)^isl(fa[x])?x:fa[x]);}inline void access(int x){ int t=0; for(;x;x=fa[x]) splay(x),ch[x][1]=t,t=x,upd(x);}inline void reverse(int x){access(x);splay(x);rev[x]^=1;}inline void link(int x,int y){reverse(x);fa[x]=y;access(x);}inline void cut(int x,int y){reverse(x);access(y);splay(y);ch[y][0]=fa[x]=0;}inline int fifa(int x){ access(x);splay(x); while(ch[x][0]) x=ch[x][0]; return x;}inline void reaD(int &x){ char Ch=getchar();x=0; for(;Ch>'9'||Ch<'0';Ch=getchar()); for(;Ch>='0'&&Ch<='9';x=x*10+Ch-'0',Ch=getchar());}int main(){ freopen("1.in","r",stdin); freopen("1.out","w",stdout); reaD(n); for(int i=1;i<=n;i++) reaD(A[i]); reaD(m); while(m--){ scanf("%s",op); if(op[0]=='b'){ reaD(x);reaD(y); if(fifa(x)==fifa(y)){puts("no");continue;} link(x,y); puts("yes"); } else if(op[0]=='e'){ reaD(x);reaD(y); if(fifa(x)!=fifa(y)){puts("impossible");continue;} reverse(x); access(y); splay(y); printf("%d\n",v[y]-v[ch[y][1]]); } else{ reaD(x);reaD(y); access(x); splay(x); A[x]=y; upd(x); } }}
0 0
- [BZOJ2843][LCT]极地旅行社
- [BZOJ2843]极地旅行社(LCT)
- 【BZOJ2843&&1180】极地旅行社,LCT练习
- bzoj2843极地旅行社题解
- BZOJ2843: 极地旅行社
- BZOJ2843极地旅行社
- 【BZOJ2843】极地旅行社
- bzoj2843 极地旅行社
- bzoj2843 极地旅行社
- BZOJ2843——极地旅行社
- [bzoj2843]极地旅行社 Link-Cut-Tree
- BZOJ 1180 CROATIAN 2009 OTOCI/2843 极地旅行社 LCT
- bzoj2843 -- LCT
- bzoj 2843 极地旅行社
- bzoj 2843: 极地旅行社
- bzoj 2843 极地旅行社
- bzoj 2843: 极地旅行社
- 2843: 极地旅行社
- C# 反射泛型
- Python IE、Chrome和Firefox运行
- Android6.0设备上动态获取权限
- (一) RabbitMQ简介
- Spark RDD算子介绍
- [BZOJ2843][LCT]极地旅行社
- Centos安装jre-8u121-linux-x64.tar.gz
- git merge 和git rebase
- CMake使用简介(for Linux)
- Linux驱动技术(五) _设备阻塞/非阻塞读写
- 传递动态内存
- Python爬虫小实践:使用BeautifulSoup+Request爬取CSDN博客的个人基本信息
- 蓝桥杯 2016 7 剪邮票
- java中作用域public private protected 以及不写的区别