hdu KiKi's K-Number 主席树
KiKi's K-Number
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
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?
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.
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
6
Not Find!
2
2
4
Not Find!
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e5+,M=1e6+,inf=2e9;
const ll INF=1e18+,mod=;
struct Chairmantree
{
int rt[N*],ls[N*],rs[N*],sum[N*];
int tot;
void init()
{
tot=;
}
void build(int l,int r,int &pos)
{
pos=++tot;
sum[pos]=;
if(l==r)return;
int mid=(l+r)>>;
build(l,mid,ls[pos]);
build(mid+,r,rs[pos]);
}
void update(int p,int c,int pre,int l,int r,int &pos)
{
pos=++tot;
ls[pos]=ls[pre];
rs[pos]=rs[pre];
sum[pos]=sum[pre]+c;
if(l==r)return;
int mid=(l+r)>>;
if(p<=mid)
update(p,c,ls[pre],l,mid,ls[pos]);
else
update(p,c,rs[pre],mid+,r,rs[pos]);
}
int rank(int s,int e,int L,int R,int l,int r)
{
if(L<=l&&r<=R)return sum[e]-sum[s];
int mid=(l+r)>>;
int ans=;
if(L<=mid)
ans+=rank(ls[s],ls[e],L,R,l,mid);
if(R>mid)
ans+=rank(rs[s],rs[e],L,R,mid+,r);
return ans;
}
int query(int L,int R,int l,int r,int k)
{
if(l==r)return l;
int mid=(l+r)>>;
int x=sum[ls[R]]-sum[ls[L]];
if(k<=x) return query(ls[L],ls[R],l,mid,k);
else return query(rs[L],rs[R],mid+,r,k-x);
}
};
Chairmantree tree;
int main()
{
int n,le=1e5+;
while(~scanf("%d",&n))
{
tree.init();
tree.build(,le,tree.rt[]);
for(int i=;i<=n;i++)
{
int x;
scanf("%d",&x);
if(x==)
{
int z;
scanf("%d",&z);
tree.update(z,,tree.rt[i-],,le,tree.rt[i]);
}
else if(x==)
{
int z;
scanf("%d",&z);
if(tree.rank(tree.rt[],tree.rt[i-],z,z,,le))
{
tree.update(z,-,tree.rt[i-],,le,tree.rt[i]);
}
else
{
tree.update(z,,tree.rt[i-],,le,tree.rt[i]);
printf("No Elment!\n");
}
}
else
{
tree.update(,,tree.rt[i-],,le,tree.rt[i]);
int a,k;
scanf("%d%d",&a,&k);
int v=tree.rank(tree.rt[],tree.rt[i],,a,,le);
k+=v;
int q=tree.rank(tree.rt[],tree.rt[i],,le,,le);
//cout<<"xxxx "<<v<<" "<<k<<" "<<q<<endl;
if(k>q)
printf("Not Find!\n");
else
printf("%d\n",tree.query(tree.rt[],tree.rt[i],,le,k));
}
//for(int j=1;j<=9;j++)
//cout<<"xxx "<<j<<" "<<tree.rank(tree.rt[0],tree.rt[i],j,j,1,le)<<endl;
}
}
return ;
}
hdu KiKi's K-Number 主席树的更多相关文章
- 计蒜客 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 ...
- HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)
HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...
- poj2104 k-th number 主席树入门讲解
poj2104 k-th number 主席树入门讲解 定义:主席树是一种可持久化的线段树 又叫函数式线段树 刚开始学是不是觉得很蒙逼啊 其实我也是 主席树说简单了 就是 保留你每一步操作完成之后 ...
- poj 2104 K-th Number 主席树+超级详细解释
poj 2104 K-th Number 主席树+超级详细解释 传送门:K-th Number 题目大意:给出一段数列,让你求[L,R]区间内第几大的数字! 在这里先介绍一下主席树! 如果想了解什么是 ...
- hdu 2665 Kth number 主席树
Kth number Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Prob ...
- 【POJ】2104 K-th Number(区间k大+主席树)
http://poj.org/problem?id=2104 裸题不说.主席树水过. #include <cstdio> #include <iostream> #includ ...
- POJ 2104 K-th Number 主席树(区间第k大)
题目链接: http://poj.org/problem?id=2104 K-th Number Time Limit: 20000MSMemory Limit: 65536K 问题描述 You ar ...
- HDU 4417 Super Mario(主席树 区间不超过k的个数)题解
题意:问区间内不超过k的个数 思路:显然主席树,把所有的值离散化一下,然后主席树求一下小于等于k有几个就行.注意,他给你的k不一定包含在数组里,所以问题中的询问一起离散化. 代码: #include& ...
- HDU - 2665 Kth number 主席树/可持久化权值线段树
题意 给一个数列,一些询问,问$[l,r]$中第$K$大的元素是哪一个 题解: 写法很多,主席树是最常用的一种之一 除此之外有:划分树,莫队分块,平衡树等 主席树的定义其实挺模糊, 一般认为就是可持久 ...
- HDU 4417 Super Mario(主席树求区间内的区间查询+离散化)
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
随机推荐
- HTML5+CSS3 表格设计(Table)
<style> body { width: 600px; margin: 40px auto; font-family: 'trebuchet MS', 'Lucida sans', Ar ...
- android 点九工具介绍
1=============================9.png简介:“点九”是andriod平台的应用软件开发里的一种特殊的图片形式,文件扩展名为:.9.png android平台有多种不同的 ...
- mysql 一对多,多对多
一对多 一对多与多对一是一个概念,指的是一个实体的某个数据与另外一个实体的多个数据有关联关系. 班级表(一表) 名称 教室 总人数 学科 PHP141115 A814 53 PHP PHP140925 ...
- FZU 2105 Digits Count
Problem 2105 Digits Count Accept: 444 Submit: 2139 Time Limit: 10000 mSec Memory Limit : 2621 ...
- With all Java versions it is strongly recommended to not use experimental -XX JVM options.
https://lucene.apache.org/solr/7_6_0//SYSTEM_REQUIREMENTS.html System Requirements Apache Solr runs ...
- python使用tesseract-ocr完成验证码识别
全自动区分计算机和人类的公开图灵测试(Completely Automated Public Turing test to tell Computers and Humans Apart) 简称CAP ...
- Python 面向对象 类 __str__
class dog(object): def __init__(self,name): self.name = name d = dog('mike') print(d) # <__main__ ...
- 一个兼职DBA的数据库运维经验 小米科技 xx@xiaomi.com 2011
一个兼职DBA的数据库运维经验 小米科技 xx@xiaomi.com 2011 内存扩容 16G->64G ,调大bp后,凌晨说监控物理内存有余量情况下,开吃swap,内存泄露措施1 定时 ...
- OCR技术浅探:Python示例(5)
文件说明: 1. image.py——图像处理函数,主要是特征提取: 2. model_training.py——训练CNN单字识别模型(需要较高性能的服务器,最好有GPU加速,否则真是慢得要死): ...
- Check out our list of adidas NMD Singapore retailers
The adidas NMD Singapore is confirmed to produce on The month of january 14th at select adidas Origi ...