1、题目大意:一道treap题,支持插入,询问第K大,还有全体修改+上一个值,如果某个点值小于x,那么就删除这个点

插入100000次,询问100000次,修改100次。。最后输出删了多少个点

2、分析:首先看修改是100次的,我就没有多想什么lazy,什么的

就是名次树,修改的话,我们就遍历treap,全部修改我们就O(n)搞一下

最后说一个坑爹的地方,就是插入前就否认的点不算T_T

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
struct Node{
    Node* ch[2];
    int r, v, s, c;
    inline bool operator < (const Node& rhs) const{
        return r < rhs.r;
    }
    inline int cmp(int x){
        if(x == v) return -1;
        if(x < v) return 0;
        return 1;
    }
    inline void maintain(){
        s = c;
        if(ch[0] != NULL) s += ch[0] -> s;
        if(ch[1] != NULL) s += ch[1] -> s;
        return;
    }
};
Node ft[500000];
struct treap{

    Node *p;
    int cnt;
    inline void init(){
        cnt = -1;
        p = NULL;
        return;
    }
    inline void rotate(Node* &o, int d){
        Node *k = o -> ch[d ^ 1];
        o -> ch[d ^ 1] = k -> ch[d];
        k -> ch[d] = o;
        o -> maintain();
        k -> maintain();
        o = k;
        return;
    }
    inline void insert(Node* &o, int x){
        if(o == NULL){
            o = &ft[++ cnt];
            o -> ch[0] = o -> ch[1] = NULL;
            o -> v = x;
            o -> r = rand();
            o -> c = 1;
        }
        else if(o -> v == x) o -> c ++;
        else{
            int d = o -> cmp(x);
            insert(o -> ch[d], x);
            if(o -> ch[d] -> r > o -> r) rotate(o, d ^ 1);
        }
        o -> maintain();
        return;
    }
    inline void A(Node* &o, int x){
        if(o == NULL) return;
        o -> v += x;
        A(o -> ch[0], x);
        A(o -> ch[1], x);
        return;
    }
    inline void S(Node* &o, int x){
        while(o != NULL && o -> v < x) o = o -> ch[1];
        if(o == NULL) return;
        if(o -> ch[0] != NULL) S(o -> ch[0], x);
        if(o -> ch[1] != NULL) S(o -> ch[1], x);
        if(o != NULL) o -> maintain();
        return;
    }
    inline int k_th(Node* &o, int k){
        int ls = 0, rs = 0;
        if(o -> ch[0] != NULL) ls = o -> ch[0] -> s;
        if(ls >= k) return k_th(o -> ch[0], k);
        else if(ls + o -> c >= k) return o -> v;
        else return k_th(o -> ch[1], k - ls - o -> c);
    }
} wt;
int main(){
    int n, m, orz = 0;
    scanf("%d%d", &n, &m);
    wt.init();
    for(int i = 1; i <= n; i ++){
        char str[5]; int k;
        scanf("%s%d", str, &k);
        if(str[0] == 'I'){
            if(k >= m){
                orz ++;
                wt.insert(wt.p, k);
            }
        }
        else if(str[0] == 'A') wt.A(wt.p, k);
        else if(str[0] == 'F'){
            if(wt.p == NULL || k > wt.p -> s) printf("-1\n");
            else printf("%d\n", wt.k_th(wt.p, wt.p -> s - k + 1));
        }
        else {
            wt.A(wt.p, -k);
            wt.S(wt.p, m);
        }
    }
    printf("%d\n", orz - wt.p -> s);
    return 0;
}

最新文章

  1. Thinkstation center M8600t装RHEL7不能联网,网卡驱动没装问题
  2. 2D Skeletal Animation Ready
  3. 13. 用Roberts、Sobel、Prewitt和Laplace算子对一幅灰度图像进行边缘检测。观察异同。
  4. JAVA 根据用户输入数据求某年到某年有多少天
  5. Math.trunc
  6. MAX16054
  7. javascript 正则表达式代码
  8. WPF之让ListView中的CheckBox居中显示
  9. js01-javascript语法标准和数据类型
  10. elasticsearch6.7 05. Document APIs(6)UPDATE API
  11. websocket(三)——基于node sockit.io的即时通讯
  12. CentOS7 vsftpd 安装及配置
  13. 20155208徐子涵 2016-2017-2 《Java程序设计》第8周学习总结
  14. 使用git时报错出现vim.exe.stackdump
  15. 牛客训练四:Applese 涂颜色(费马小定理+快速幂)
  16. 文件句柄FileDescriptor的hanle/fd两个字段分析
  17. 五、spring boot 1.5.4 集成 jpa+hibernate+jdbcTemplate
  18. Nginx防盗链 Nginx访问控制 Nginx解析php相关配置 Nginx代理
  19. swap file &quot;*.swp&quot; already exists!
  20. This assembly may have been downloaded from the Web. ......

热门文章

  1. hibernate......1、2级缓存
  2. vmware tools 在linux中的作用
  3. Javascript 与正则表达式
  4. GridView数据格式化
  5. jQuery关于隐式迭代的个人理解~
  6. IIS------IIS上部署MVC网站,打开后ExtensionlessUrlHandler-Integrated-4.0解决办法
  7. 利用jquery实现网站中对应栏目下面内容切换效果。
  8. SVN服务器配置说明
  9. 9月23日JavaScript作业----子菜单下拉
  10. ubuntu下samba服务器的安装与配置