KiKi's K-Number

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description
For the k-th number, we all should be very familiar with it. Of course,to kiki it is also simple. Now Kiki meets a very similar problem, kiki wants to design a container, the container is to support the three operations.

Push: Push a given element e to container

Pop: Pop element of a given e from container

Query: Given two elements a and k, query the kth larger number which greater than a in container;

Although Kiki is very intelligent, she can not think of how to do it, can you help her to solve this problem?

 
Input
Input some groups of test data ,each test data the first number is an integer m (1 <= m <100000), means that the number of operation to do. The next m lines, each line will be an integer p at the beginning, p which has three values:
If p is 0, then there will be an integer e (0 <e <100000), means press element e into Container.

If p is 1, then there will be an integer e (0 <e <100000), indicated that delete the element e from the container

If p is 2, then there will be two integers a and k (0 <a <100000, 0 <k <10000),means the inquiries, the element is greater than a, and the k-th larger number.

 
Output
For each deletion, if you want to delete the element which does not exist, the output "No Elment!". For each query, output the suitable answers in line .if the number does not exist, the output "Not Find!".
 
Sample Input
5
0 5
1 2
0 6
2 3 2
2 8 1
7
0 2
0 2
0 4
2 1 1
2 1 2
2 1 3
2 1 4
 
Sample Output
No Elment!
6
Not Find!
2
2
4
Not Find!
 
Source
  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<cmath>
  5. #include<string>
  6. #include<queue>
  7. #include<algorithm>
  8. #include<stack>
  9. #include<cstring>
  10. #include<vector>
  11. #include<list>
  12. #include<set>
  13. #include<map>
  14. using namespace std;
  15. #define ll long long
  16. #define pi (4*atan(1.0))
  17. #define eps 1e-14
  18. #define bug(x) cout<<"bug"<<x<<endl;
  19. const int N=1e5+,M=1e6+,inf=2e9;
  20. const ll INF=1e18+,mod=;
  21. struct Chairmantree
  22. {
  23. int rt[N*],ls[N*],rs[N*],sum[N*];
  24. int tot;
  25. void init()
  26. {
  27. tot=;
  28. }
  29. void build(int l,int r,int &pos)
  30. {
  31. pos=++tot;
  32. sum[pos]=;
  33. if(l==r)return;
  34. int mid=(l+r)>>;
  35. build(l,mid,ls[pos]);
  36. build(mid+,r,rs[pos]);
  37. }
  38. void update(int p,int c,int pre,int l,int r,int &pos)
  39. {
  40. pos=++tot;
  41. ls[pos]=ls[pre];
  42. rs[pos]=rs[pre];
  43. sum[pos]=sum[pre]+c;
  44. if(l==r)return;
  45. int mid=(l+r)>>;
  46. if(p<=mid)
  47. update(p,c,ls[pre],l,mid,ls[pos]);
  48. else
  49. update(p,c,rs[pre],mid+,r,rs[pos]);
  50. }
  51. int rank(int s,int e,int L,int R,int l,int r)
  52. {
  53. if(L<=l&&r<=R)return sum[e]-sum[s];
  54. int mid=(l+r)>>;
  55. int ans=;
  56. if(L<=mid)
  57. ans+=rank(ls[s],ls[e],L,R,l,mid);
  58. if(R>mid)
  59. ans+=rank(rs[s],rs[e],L,R,mid+,r);
  60. return ans;
  61. }
  62. int query(int L,int R,int l,int r,int k)
  63. {
  64. if(l==r)return l;
  65. int mid=(l+r)>>;
  66. int x=sum[ls[R]]-sum[ls[L]];
  67. if(k<=x) return query(ls[L],ls[R],l,mid,k);
  68. else return query(rs[L],rs[R],mid+,r,k-x);
  69. }
  70. };
  71. Chairmantree tree;
  72. int main()
  73. {
  74. int n,le=1e5+;
  75. while(~scanf("%d",&n))
  76. {
  77. tree.init();
  78. tree.build(,le,tree.rt[]);
  79. for(int i=;i<=n;i++)
  80. {
  81. int x;
  82. scanf("%d",&x);
  83. if(x==)
  84. {
  85. int z;
  86. scanf("%d",&z);
  87. tree.update(z,,tree.rt[i-],,le,tree.rt[i]);
  88. }
  89. else if(x==)
  90. {
  91. int z;
  92. scanf("%d",&z);
  93. if(tree.rank(tree.rt[],tree.rt[i-],z,z,,le))
  94. {
  95. tree.update(z,-,tree.rt[i-],,le,tree.rt[i]);
  96. }
  97. else
  98. {
  99. tree.update(z,,tree.rt[i-],,le,tree.rt[i]);
  100. printf("No Elment!\n");
  101. }
  102. }
  103. else
  104. {
  105. tree.update(,,tree.rt[i-],,le,tree.rt[i]);
  106. int a,k;
  107. scanf("%d%d",&a,&k);
  108. int v=tree.rank(tree.rt[],tree.rt[i],,a,,le);
  109. k+=v;
  110. int q=tree.rank(tree.rt[],tree.rt[i],,le,,le);
  111. //cout<<"xxxx "<<v<<" "<<k<<" "<<q<<endl;
  112. if(k>q)
  113. printf("Not Find!\n");
  114. else
  115. printf("%d\n",tree.query(tree.rt[],tree.rt[i],,le,k));
  116. }
  117. //for(int j=1;j<=9;j++)
  118. //cout<<"xxx "<<j<<" "<<tree.rank(tree.rt[0],tree.rt[i],j,j,1,le)<<endl;
  119. }
  120. }
  121. return ;
  122. }

hdu KiKi's K-Number 主席树的更多相关文章

  1. 计蒜客 38229.Distance on the tree-1.树链剖分(边权)+可持久化线段树(区间小于等于k的数的个数)+离散化+离线处理 or 2.树上第k大(主席树)+二分+离散化+在线查询 (The Preliminary Contest for ICPC China Nanchang National Invitational 南昌邀请赛网络赛)

    Distance on the tree DSM(Data Structure Master) once learned about tree when he was preparing for NO ...

  2. HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)

    HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...

  3. poj2104 k-th number 主席树入门讲解

    poj2104 k-th number 主席树入门讲解 定义:主席树是一种可持久化的线段树 又叫函数式线段树   刚开始学是不是觉得很蒙逼啊 其实我也是 主席树说简单了 就是 保留你每一步操作完成之后 ...

  4. poj 2104 K-th Number 主席树+超级详细解释

    poj 2104 K-th Number 主席树+超级详细解释 传送门:K-th Number 题目大意:给出一段数列,让你求[L,R]区间内第几大的数字! 在这里先介绍一下主席树! 如果想了解什么是 ...

  5. hdu 2665 Kth number 主席树

    Kth number Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Prob ...

  6. 【POJ】2104 K-th Number(区间k大+主席树)

    http://poj.org/problem?id=2104 裸题不说.主席树水过. #include <cstdio> #include <iostream> #includ ...

  7. POJ 2104 K-th Number 主席树(区间第k大)

    题目链接: http://poj.org/problem?id=2104 K-th Number Time Limit: 20000MSMemory Limit: 65536K 问题描述 You ar ...

  8. HDU 4417 Super Mario(主席树 区间不超过k的个数)题解

    题意:问区间内不超过k的个数 思路:显然主席树,把所有的值离散化一下,然后主席树求一下小于等于k有几个就行.注意,他给你的k不一定包含在数组里,所以问题中的询问一起离散化. 代码: #include& ...

  9. HDU - 2665 Kth number 主席树/可持久化权值线段树

    题意 给一个数列,一些询问,问$[l,r]$中第$K$大的元素是哪一个 题解: 写法很多,主席树是最常用的一种之一 除此之外有:划分树,莫队分块,平衡树等 主席树的定义其实挺模糊, 一般认为就是可持久 ...

  10. HDU 4417 Super Mario(主席树求区间内的区间查询+离散化)

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

随机推荐

  1. Unity3D笔记五 快捷键

    一.近距离查看游戏对象 在Hierarchy视图中选择游戏对象,然后在Scene视图中按快捷键“F”来近距离查看该游戏对象. 二.游戏对象不在主摄像头中? Hierarchy中双击选择需要显示的游戏对 ...

  2. oracle的connect by level的示例

    SELECT regexp_substr('CITY_AA,CITY_BB,CITY_CC,CITY_DD', '[^,]+', 1, LEVEL) t FROM dualCONNECT BY reg ...

  3. angular -- 自定义指令和模板

    angular 可以自定义一些指令,来简化我们前端的工作量. 第一种:简单指令示例: <h3>自定义指令</h3> <sheng></sheng> &l ...

  4. ajax解决跨域方法(适用于自己写接口解决跨域)

    原因是这样的:最近用PHP开发了一个网站,这个网站需要提供接口,接口开发完成之后,在本地进行请求,跨域测试. jsonp处理跨域和用PHP函数来处理跨域就不说了. 现在说的使用用 header 这个来 ...

  5. 边的双联通+缩点+LCA(HDU3686)

    Traffic Real Time Query System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  6. JavaORM框架之Mybatis篇(Ibatis)

    欢迎查看Java开发之上帝之眼系列教程,如果您正在为Java后端庞大的体系所困扰,如果您正在为各种繁出不穷的技术和各种框架所迷茫,那么本系列文章将带您窥探Java庞大的体系.本系列教程希望您能站在上帝 ...

  7. jenkins之升级

    首先查看系统war包放置的位置 rpm -ql jenkins 下载一个war包 下载地址 https://mirrors.tuna.tsinghua.edu.cn/jenkins/war/2.61/ ...

  8. Oracle下Delete语句

    Delete语句 基本语法: delete from 表名 where 条件 注意事项: 1,如果不使用where子句,将表中所有数据全部删除 delete from test; 2,如果要删除某列的 ...

  9. c# 读取confgi文件

    引用命名空间using System.Configuration; Winform—C#读写config配置文件

  10. ubuntu 下安装 jdk

    1. 下载 jdk : https://www.oracle.com/technetwork/java/javase/downloads/index.html 2. 解压 jdk 到系统默认 jdk ...