poj2761——treap,区间第K小值

题意:求区间第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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值