POJ 2761 Feed the dogs
主席树,区间第$k$大。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar(); x = ;while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} const int maxn=;
int a[maxn],b[maxn],root[maxn],n,m,sz;
struct Node {int l,r,sum;} s[maxn*]; int get(int x)
{
int L=,R=n,res;
while(L<=R)
{
int mid=(L+R)/;
if(b[mid]>x) R=mid-;
else if(b[mid]<x) L=mid+;
else res=mid,R=mid-;
}
return res;
} void update(int l,int r,int &x,int y,int p)
{
sz++; s[sz]=s[y]; s[sz].sum++; x=sz;
if(l==r) return;
int mid=(l+r)/;
if(p<=mid) update(l,mid,s[sz].l,s[y].l,p);
else update(mid+,r,s[sz].r,s[y].r,p);
} int quary(int l,int r,int x,int y,int p)
{
if(l==r) return l;
int mid=(l+r)/;
int tmp=s[s[y].l].sum-s[s[x].l].sum;
if(tmp>=p) return quary(l,mid,s[x].l,s[y].l,p);
else return quary(mid+,r,s[x].r,s[y].r,p-tmp);
} int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) scanf("%d",&a[i]),b[i]=a[i];
sort(b+,b++n); for(int i=;i<=n;i++) a[i]=get(a[i]);
for(int i=;i<=n;i++) update(,n,root[i],root[i-],a[i]);
for(int i=;i<=m;i++)
{
int L,R,k; scanf("%d%d%d",&L,&R,&k);
printf("%d\n",b[quary(,n,root[L-],root[R],k)]);
}
return ;
}
POJ 2761 Feed the dogs的更多相关文章
- poj 2761 Feed the dogs (treap树)
/************************************************************* 题目: Feed the dogs(poj 2761) 链接: http: ...
- POJ 2761 Feed the dogs(平衡树or划分树or主席树)
Description Wind loves pretty dogs very much, and she has n pet dogs. So Jiajia has to feed the dogs ...
- POJ 2761 Feed the dogs (主席树)(K-th 值)
Feed the dogs Time Limit: 6000MS Memor ...
- POJ 题目2761 Feed the dogs(主席树||划分树)
Feed the dogs Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 16860 Accepted: 5273 De ...
- 划分树---Feed the dogs
POJ 2761 Description Wind loves pretty dogs very much, and she has n pet dogs. So Jiajia has to fee ...
- 【POJ2761】【区间第k大】Feed the dogs(吐槽)
Description Wind loves pretty dogs very much, and she has n pet dogs. So Jiajia has to feed the dogs ...
- poj 2761 主席树的应用(查询区间第k小值)
Feed the dogs Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 22084 Accepted: 7033 De ...
- [POJ2761] Feed the dogs (Treap)
题目链接:http://poj.org/problem?id=2761 题目大意:给你n个数,m次查询,m次查询分别是a,b,k,查询下表从a到b的第k小元素是哪个.这m个区间不会互相包含. Trea ...
- 【poj2761】 Feed the dogs
http://poj.org/problem?id=2761 (题目链接) 题意 求区间第K大. Solution 和poj2104一模一样. 主席树代码 // poj2761 #include< ...
随机推荐
- 理解对象模型图(Reading OMDS)
理解对象模型图(Reading OMDS) 引言 这篇文章大部分内容是翻译的帮助资料里的东西.学习技术,英语是个好工具.一直把英语的地位看得和技术一样重,也会强迫自己看英语版的技术书籍(都是PDF版的 ...
- Grub禁用UUID
这个属于一个个人喜好问题,我每次看到 df -h 的结果都很郁闷,根目录那一行设备是用uuid表示的,那一串字符真是够长的,看起来非常别扭,所以就自己修改了一下/etc/default/grub文件. ...
- 实践Scrum
http://blog.vsharing.com/agiledo/ [原创]敏捷开发实践-我们这样实践Scrum-续(81页) 我们团队实践Scrum,有一些做法和教训,希望和大家分享: 公司背景:通 ...
- FAQ:仓储实现为什么在基础设施层?
FAQ:仓储实现为什么在基础设施层? 目录 问答部分参考文章 问答部分返回目录 问: 仓储实现为什么在基础设施层? 答: 领域模型包含三种元素:实体.值对象和服务,这三种元素都可以以某种形式使用仓储, ...
- 【DOS】这个命令太牛逼了
删除一个程序了后 竟然上不了网了 运行下列命令重启后就可以了 实在是救了我系统一命 命令如下: netsh winsock reset
- HttpStack及其实现类
HttpStack及其实现类 前两篇已经对网络请求流程已经梳理了个大概,这次我们着重看一下HttpStack和它的其实现类.我们之前在Network篇讲过它仅有一个实现类,而今天我们讲的HttpSta ...
- enode框架step by step之saga的思想与实现
enode框架step by step之saga的思想与实现 enode框架系列step by step文章系列索引: 分享一个基于DDD以及事件驱动架构(EDA)的应用开发框架enode enode ...
- 64位CentOS 6.0下搭建LAMP环境
系统环境:Centos6.0 x64 1.确认搭建LAMP所需要的环境是否已经安装 [root@centos6 ~]# rpm -q make gcc gcc-c++ zlib-devel libai ...
- SQL Server 2014新特性:五个关键点带你了解Excel下的Data Explorer
SQL Server 2014新特性:五个关键点带你了解Excel下的Data Explorer Data Explorer是即将发布的SQL Server 2014里的一个新特性,借助这个特性讲使企 ...
- java自动生成略缩图
当你要做一个图库的项目时,对图片大小.像素的控制是首先需要解决的难题. 本篇文章,在前辈的经验基础上,分别对单图生成略缩图和批量生成略缩图做个小结. 一.单图生成略缩图 单图经过重新绘制,生成新的图片 ...