模板

· · 个人记录

FHQ Treap

#include <bits/stdc++.h>
using namespace std;
const int MAXN = /*MAXN*/;
int rt, tot, w[MAXN], l[MAXN], r[MAXN], rd[MAXN];
// Define other things
void pushup(int x) {
    // Push up;
}
void pushdown(int x) {
    // Push down
}
int newnd(int x) {
    w[++tot] = x;
    rd[tot] = rand();
    // Mark other things
    return tot;
}
void split(int u, int x, int &a, int &b) {
    if (!u) {
        a = b = 0;
        return;
    }
    pushdown(u);
    if (w[u] <= x) {
        a = u;
        split(r[u], x, r[u], b);
    } else {
        b = u;
        split(l[u], x, a, l[u]);
    }
    pushup(u);
}
int merge(int a, int b) {
    if (!a or !b) return a | b;
    if (rd[a] < rd[b]) {
        pushdown(a);
        r[a] = merge(r[a], b);
        pushup(a);
        return a;
    } else {
        pushdown(b);
        l[b] = merge(a, l[b]);
        pushup(b);
        return b;
    }
}
void insert(int x) {
    int a, b;
    split(rt, x - 1, a, b);
    rt = merge(a, merge(newnd(x), b));
}
void remove(int x) {
    int a, b, c;
    split(rt, x-1, a, b);
    split(b, x, b, c);
    rt = merge(a, merge(merge(l[b], r[b]), c));
}
// Many other operations
int n, m;
int main() {
    // Function Main
    return 0;
}

线段树分治

#include <bits/stdc++.h>
using namespace std;
const int MAXN = /*MAXN*/;
struct Operation {
    int l, r;
    // Define other things
} ope[MAXN];
vector<int> val[MAXN];
void update(int u, int l, int r, int L, int R, int x) {
    if (l > R or r < L) return;
    if (L <= l and r <= R) return val[u].push_back(x);
    int md = l + r >> 1;
    update(u<<1, l, md, L, R, x);
    update(u<<1|1, md+1, r, L, R, x);   
}
void solve(int u, int l, int r) {
    bool flag = true;
    // Mark
    for (int i : val[u]) {
        if (/*False*/) {
            for (int j = l; j <= r; j++) /*Mark false*/;
            flag = false;
            break;
        }
        // Do operation
    }
    if (flag) {
        int md = l + r >> 1;
        if (l == r) /*Mark true*/;
        else {
            solve(u<<1, l, md);
            solve(u<<1|1, md+1, r);
        }
    }
    // Roll back to the save
}
int main() {
    // Main function
    return 0;
}