题意:求区间第K小值,待查询的区间之间不会有某一个包含另一个情况。
离线处理,把所有查询按左端点的大小排序,由条件可以得出排序后所有查询的右端点一定也是递增的。那我们就可以按顺序处理这些查询,同时更新treap,而且每个元素最多被插入到treap中一次,最多被删除一次。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int maxn = 100000 + 10;
struct node
{
node * ch[2];
int r, v, s;
inline bool operator < (const node & rhs) const { return r < rhs.r; }
inline int cmp(int x) const
{
if(x == v) return -1;
return x < v ? 0 : 1;
}
inline void pushup()
{
s = 1;
if(ch[0] != NULL) s += ch[0]->s;
if(ch[1] != NULL) s += ch[1]->s;
}
};
struct pp
{
int l, r, k, ord;
bool operator < (const pp & rhs) const { return l < rhs.l; }
}que[maxn];
int n, m, num[maxn], ans[maxn