1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| int merge(int x,int y){ if(!x || !y) return x|y; if(t[x].key>t[y].key) swap(x,y); t[t[x].rs=merge(t[x].rs,y)].fa=x; if(t[t[x].rs].d>t[t[x].ls].d) swap(t[x].ls,t[x].rs); t[x].d=t[t[x].rs].d+1; return x; }
void build(){ int l=1,r=n; for(int i=1;i<n;i++){ h[++r]=merge(h[l],h[l+1]); l+=2; } }
void pushup(int x){ if(!x) return; if(t[x].d!=t[t[x].rs].d+1){ t[x].d=t[t[x].rs].d+1; pushup(t[x].fa); } }
int merge(int x,int y){ if(!x || !y) return x|y; if(t[x].key>t[y].key) swap(x,y); t[t[x].rs=merge(t[x].rs,y)].fa=x; if(t[t[x].rs].d>t[t[x].ls].d) swap(t[x].ls,t[x].rs); pushup(x); return x; }
int pop(int x){ return merge(t[x].ls,t[x].rs); }
int merge(int x,int y){ if(!x || !y) return x|y; if(t[x].key>t[y].key) swap(x,y); pushdown(x); t[t[x].rs=merge(t[x].rs,y)].fa=x; if(t[t[x].rs].d>t[t[x].ls].d) swap(t[x].ls,t[x].rs); pushup(x); return x; }
int pop(int x){ pushdown(x); return merge(t[x].ls,t[x].rs); }
int merge(int x,int y){ if(!x || !y) return x|y; if(t[x].key>t[y].key) swap(x,y); if(rand()&1) swap(t[x].ls,t[x].rs); t[x].ls=merge(t[x].ls,y); return x; }
void pushup(int x){ if(!x) return; if(t[x].d!=t[t[x].rs].d+1){ t[x].d=t[t[x].rs].d+1; pushup(t[x].fa); } }
int merge(int x,int y){ if(!x || !y) return x|y; if(t[x].key>t[y].key) swap(x,y); pushdown(x); t[t[x].rs=merge(t[x].rs,y)].fa=x; if(t[t[x].rs].d>t[t[x].ls].d) swap(t[x].ls,t[x].rs); pushup(x); return x; }
int pop(int x){ pushdown(x); return merge(t[x].ls,t[x].rs); }
|