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
#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 主席树的更多相关文章

  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. java如何计算两个日期之间相差多少天?

    java如何计算两个日期之间相差多少天? public static void main(String [] args) { Date now = new Date(); Calendar cal = ...

  2. oracle的cursor

    oracle的cursor 转自:http://www.cnblogs.com/shengtianlong/archive/2010/12/31/1922767.html 1,什么是游标? ①从表中检 ...

  3. 网络流SAP+gap+弧优化算法

    poj1273 Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 54962   Accept ...

  4. Feature Tools 简介

    FeatureTools是2017年9月上线的github项目,是一个自动生成特征的工具,应用于关系型数据. github链接:https://github.com/Featuretools/feat ...

  5. python 10分钟入门pandas

    本文是对pandas官方网站上<10 Minutes to pandas>的一个简单的翻译,原文在这里.这篇文章是对pandas的一个简单的介绍,详细的介绍请参考:Cookbook .习惯 ...

  6. vue 引入通用 css

    1.在入口 js 文件 main.js 中引入,一些公共的样式文件,可以在这里引入. import Vue from 'vue' import App from './App' // 引入App这个组 ...

  7. 'Settings' object has no attribute 'TEMPLATE_DEBUG' 的解决方法

    找到该Django项目下的settings文件,把 DEBUG = True 改为 DEBUG = False 就可以正常浏览显示了 参考:https://stackoverflow.com/ques ...

  8. java 标识符与变量

    一.Java 标识符三要素 1.标识符由字母.下划线(_).美元符号($)或者字母组成. 2.标识符应以字母.下划线(_).美元符开头. 3.标识符字符大小写敏感,长度无限制. 标识符最重要的就是 见 ...

  9. jira-source--plugin

    X11 forward impact on jira plugin system initialization. 而Linux的curl使用的证书库在文件“/etc/pki/tls/certs/ca- ...

  10. docker 离线环境安装oracle

    因测试需要,需在内网的测试环境搭建一套docker Oracle 11g环境进行测试,测试环境为redhat 6.6 安装docker 1.7,本机windows 7 环境,安装docker 17.1 ...