国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

[BZOJ1180][CROATIAN2009][LCT]OTOCI

2019-11-14 09:51:41
字體:
來源:轉載
供稿:網友

LCT裸題吧….就是沒有cut而已

#include <cstdio>#define N 50010int n,m;int v[N],f[N],ch[N][2],rev[N],fa[N],t[N],sta[N],tp;char op[20];inline char C(){ static char buf[100000],*p1=buf,*p2=buf; if(p1==p2){ p2=(p1=buf)+fread(buf,1,100000,stdin); if(p1==p2) return EOF; } return *p1++;}inline void reaD(int &x){ char Ch=C();x=0; for(;Ch>'9'||Ch<'0';Ch=C()); for(;Ch>='0'&&Ch<='9';x=x*10+Ch-'0',Ch=C());}inline void reaD(char *x){ char Ch=C();int len=0; for(;Ch>'z'||Ch<'a';Ch=C()); for(;Ch>='a'&&Ch<='z';x[++len]=Ch,Ch=C());}int fifa(int x){return x==fa[x]?x:fa[x]=fifa(fa[x]);}inline void swap(int &x,int &y){int z=x;x=y;y=z;}inline int isr(int x){return ch[f[x]][0]!=x&&ch[f[x]][1]!=x;}inline int isl(int x){return ch[f[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){ t[x]=v[x]; if(ch[x][0]) t[x]+=t[ch[x][0]]; if(ch[x][1]) t[x]+=t[ch[x][1]];}inline void rot(int x){ int y=f[x],z=f[y],lor=isl(x); if(!isr(y)) ch[z][ch[z][1]==y]=x; f[x]=z;ch[y][lor]=ch[x][lor^1]; if(ch[y][lor]) f[ch[y][lor]]=y; ch[x][lor^1]=y;f[y]=x; upd(y);upd(x);}inline void splay(int x){ sta[tp=1]=x; for(int i=x;!isr(i);i=f[i]) sta[++tp]=f[i]; for(;tp;tp--) pushdown(sta[tp]); for(;!isr(x);rot(x))if(!isr(f[x])) if(isl(x)^isl(f[x])) rot(x); else rot(f[x]);}inline void access(int x){int t=0;for(;x;t=x,x=f[x])splay(x),ch[x][1]=t,upd(x);}inline void reverse(int x){access(x);splay(x);rev[x]^=1;}inline int query(int x,int y){reverse(x);access(y);splay(y);return t[y];}inline void link(int x,int y){reverse(x);f[x]=y;splay(x);}inline void change(int x,int y){reverse(x);v[x]=y;upd(x);}int w[20],wt;inline void Pt(int x){ if(!x){putchar(48);putchar('/n');return;} while(x)w[++wt]=x%10,x/=10; for(;wt;wt--)putchar(48+w[wt]);putchar('/n');}int main(){ reaD(n); for(int i=1;i<=n;i++) reaD(v[i]),fa[i]=i; reaD(m); for(int i=1,x,y;i<=m;i++){ reaD(op);reaD(x);reaD(y); if(op[1]=='e') if(fifa(x)==fifa(y)) Pt(query(x,y)); else puts("impossible"); else if(op[1]=='b') if(fifa(x)==fifa(y)) puts("no"); else puts("yes"),link(x,y),fa[fifa(x)]=fifa(y); else change(x,y); }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 万荣县| 错那县| 盐城市| 灵武市| 兴义市| 南开区| 西安市| 阿坝县| 南陵县| 泸西县| 饶阳县| 阜城县| 新营市| 同德县| 巴彦县| 青州市| 龙海市| 博客| 攀枝花市| 乐山市| 河津市| 遂溪县| 锡林浩特市| 边坝县| 连平县| 社会| 东至县| 凌云县| 阳西县| 托克逊县| 抚顺县| 开鲁县| 莫力| 岳池县| 民县| 华池县| 琼结县| 龙岩市| 无棣县| 通许县| 永顺县|