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

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

[BZOJ3282][LCT]Tree

2019-11-14 10:37:56
字體:
供稿:網(wǎng)友

題意


對于一張無向圖,需要你支持加邊,刪邊,求路徑疑惑和,修改權(quán)值四個操作


真丶LCT裸題

#include <cstdio>#define N 300010int n,m,op,x,y,tp;int v[N],w[N],f[N],ch[N][2],rev[N],sta[N];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());}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 upd(int x){ if(!x) return; v[x]=w[x]; if(ch[x][0]) v[x]^=v[ch[x][0]]; if(ch[x][1]) v[x]^=v[ch[x][1]];}inline void swap(int &x,int &y){int z=x;x=y;y=z;}inline void pushdown(int x){ if(!(x&&rev[x])) return ; swap(ch[x][0],ch[x][1]); if(ch[x][1]) rev[ch[x][1]]^=1; if(ch[x][0]) rev[ch[x][0]]^=1; rev[x]=0;}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]))rot(isl(f[x])^isl(x)?x: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 fifa(int x){access(x);splay(x);while(ch[x][0])x=ch[x][0];return x;}inline int query(int x,int y){reverse(x);access(y);splay(y);return v[y];}inline void link(int x,int y){reverse(x);f[x]=y;splay(x);}inline void cut(int x,int y){reverse(x);access(y);splay(y);ch[y][0]=f[x]=0;}inline void change(int x,int y){access(x);splay(x);w[x]=y;upd(x);}int main(){ reaD(n);reaD(m); for(int i=1;i<=n;i++) reaD(w[i]); for(int i=1;i<=m;i++){ reaD(op);reaD(x);reaD(y); if(op==0)
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 临邑县| 深州市| 伊川县| 嘉义县| 凤阳县| 青铜峡市| 凤庆县| 北流市| 那曲县| 定襄县| 利川市| 山东省| 二连浩特市| 闽侯县| 桐乡市| 尉犁县| 三门县| 安康市| 远安县| 宝坻区| 安庆市| 三穗县| 定西市| 南江县| 隆安县| 凤翔县| 互助| 赫章县| 荔波县| 宣汉县| 昌黎县| 昌宁县| 温州市| 抚远县| 延庆县| 陆川县| 十堰市| 赤水市| 昂仁县| 丰县| 嘉定区|