刚写完线段树套splay的,回头补上树状数组套主席树的;
线段树套splay的思路:
每个线段树节点上有一棵splay里面存对应区间内的所有数字;修改时直接在每个splay上进行删除节点后再添加;查询时二分值判断是第多少大的,向大逼近;
每个线段树节点上有一棵splay里面存对应区间内的所有数字;修改时直接在每个splay上进行删除节点后再添加;查询时二分值判断是第多少大的,向大逼近;
代码还是一贯的长。。。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int Inf = 0x3f3f3f;
const int maxn = 51000;
inline int getnum() {
int ans = 0, f = 1;
char c = getchar();
if(c == '-') f = -1;
while(c < '0' || c > '9') c = getchar();
while(c >= '0' && c <= '9') ans += c - '0', c = getchar();
return ans*f;
}
int n, m, tot;
int ch[maxn*20][2], size[maxn*20], p[maxn*20], cnt[maxn*20], key[maxn*20];
int c[maxn