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

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

【bzoj3224】文藝平衡樹

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

壓了好久了,splay區間翻轉的模板,我的好多模板都是照zyf2000寫的。同樣貼代碼跑.

#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm> using namespace std;const int maxn=110000,inf=10000000;int ch[maxn][2],f[maxn],size[maxn],key[maxn],delta[maxn],a[maxn]; int n,m,x,y,root,sz;void updata(int x){ size[x]=size[ch[x][0]]+size[ch[x][1]]+1;}bool get(int x){return ch[f[x]][1]==x;}void pushdown(int x){ if (x&&delta[x]) { delta[ch[x][1]]^=1; delta[ch[x][0]]^=1; swap(ch[x][0],ch[x][1]); delta[x]=0; }}int build(int l,int r,int fa){ if (l>r)return 0; int mid=(l+r)>>1; int now=++sz; key[now]=a[mid];f[now]=fa;delta[now]=0; int leftchild=build(l,mid-1,now); int rightchild=build(mid+1,r,now); ch[now][0]=leftchild;ch[now][1]=rightchild;updata(now); return now; }void rotate (int x){ pushdown(f[x]);pushdown(x); int old=f[x],oldf=f[old],which=get(x); ch[old][which]=ch[x][which^1];f[ch[old][which]]=old; ch[x][which^1]=old;f[old]=x; f[x]=oldf; if (oldf) ch[oldf][ch[oldf][1]==old]=x; updata(old);updata(x); }void splay(int x,int tar){ for (int fa;(fa=f[x])!=tar;rotate(x)) if (f[fa]!=tar) rotate((get(x)==get(fa))?fa:x); if(tar==0) root=x; }int find(int x){ int now=root; while(1) { pushdown(now); if (x<=size[ch[now][0]]) now=ch[now][0]; else { x-=size[ch[now][0]]+1; if (x==0)return now; now=ch[now][1]; } } } void PRint(int now){ pushdown(now); if (ch[now][0])print(ch[now][0]); if (key[now]!=inf&&key[now]!=-inf)printf("%d ",key[now]); if (ch[now][1])print(ch[now][1]);}int main(){ scanf("%d%d",&n,&m); a[1]=-inf;a[n+2]=inf; for (int i=1;i<=n;i++) a[i+1]=i; sz=0; root=build(1,n+2,0); for (int i=1;i<=m;i++) { scanf("%d%d",&x,&y); if (x>=y)continue; int aa=find(x); int bb=find(y+2); splay(aa,0); splay(bb,aa); delta[ch[ch[root][1]][0]]^=1; } print(root);}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 博野县| 舒兰市| 德阳市| 墨玉县| 三原县| 蕲春县| 辉县市| 涡阳县| 客服| 嘉兴市| 湄潭县| 怀来县| 清水县| 吴江市| 连云港市| 苏尼特左旗| 昆山市| 阳泉市| 辽宁省| 怀柔区| 特克斯县| 札达县| 陆河县| 和龙市| 密云县| 铜鼓县| 乡城县| 多伦县| 辉县市| 荥阳市| 资阳市| 古浪县| 五莲县| 德州市| 寿宁县| 康乐县| 漳州市| 铜川市| 秦皇岛市| 屏南县| 遂溪县|