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

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

[BZOJ1180][CROATIAN2009][LCT]OTOCI

2019-11-14 09:55:47
字體:
供稿:網(wǎng)友

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); }}
上一篇:文章標題

下一篇:快排算法

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 绥滨县| 邛崃市| 伊宁县| 武乡县| 湘阴县| 特克斯县| 临泽县| 五指山市| 山东省| 五河县| 屏南县| 高州市| 陆丰市| 汉中市| 乌鲁木齐县| 共和县| 周至县| 孟津县| 台北县| 桦南县| 盐源县| 福州市| 同江市| 襄城县| 永川市| 双江| 穆棱市| 青阳县| 普陀区| 广德县| 大石桥市| 靖宇县| 莱芜市| 河曲县| 麻栗坡县| 开江县| 深泽县| 普宁市| 太康县| 珲春市| 新巴尔虎右旗|