洛谷P3391 文艺平衡术 非旋转treap

luogu 3391

这题涉及到区间操作 emmm Splay可以很好胜任

不过谢谢非旋转treap的把 操作和之前的treap(不好意思没发 因为用非旋重新实现了之前的普通平衡树

之前down忘记在split里操作 WA了一发

看代码把

/*
luogu 3369
*/
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
const int MAX_N = 500010;

int siz[MAX_N],ch[MAX_N][2],rnd[MAX_N],val[MAX_N],fl[MAX_N];
int T,cnt,m,x,y,z,p,a,root,rt,com;

int read(){
    int x = 0,f = 1;char c = getchar();
    while(c>'9'||c<'0') {if(c=='-') f =-1;c = getchar();}
    while(c>='0'&&c<='9') {x = x*10 + c - '0';c = getchar();}
    return x * f;
}

void update(int x){
    siz[x] = 1 + siz[ch[x][0]] + siz[ch[x][1]];
}

void down(int now){
    swap(ch[now][0],ch[now][1]);
    if(ch[now][0]) fl[ch[now][0]]^=1;
    if(ch[now][1]) fl[ch[now][1]]^=1;
    fl[now] = 0;
}
int Insert(int a){
    siz[++cnt] = 1;
    val[cnt] = a;
    rnd[cnt] = rand();
    return cnt;
}

int Merge(int A,int B){
    if(!A||!B) return A+B;
    if(rnd[A]

 

你可能感兴趣的:(ACM,Treap)