博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ2761 Feed the dogs
阅读量:6846 次
发布时间:2019-06-26

本文共 2995 字,大约阅读时间需要 9 分钟。

 

 
Time Limit: 6000MS   Memory Limit: 65536KB   64bit IO Format: %lld & %llu

Description

Wind loves pretty dogs very much, and she has n pet dogs. So Jiajia has to feed the dogs every day for Wind. Jiajia loves Wind, but not the dogs, so Jiajia use a special way to feed the dogs. At lunchtime, the dogs will stand on one line, numbered from 1 to n, the leftmost one is 1, the second one is 2, and so on. In each feeding, Jiajia choose an inteval[i,j], select the k-th pretty dog to feed. Of course Jiajia has his own way of deciding the pretty value of each dog. It should be noted that Jiajia do not want to feed any position too much, because it may cause some death of dogs. If so, Wind will be angry and the aftereffect will be serious. Hence any feeding inteval will not contain another completely, though the intervals may intersect with each other. 
Your task is to help Jiajia calculate which dog ate the food after each feeding. 

Input

The first line contains n and m, indicates the number of dogs and the number of feedings. 
The second line contains n integers, describe the pretty value of each dog from left to right. You should notice that the dog with lower pretty value is prettier. 
Each of following m lines contain three integer i,j,k, it means that Jiajia feed the k-th pretty dog in this feeding. 
You can assume that n<100001 and m<50001. 

Output

Output file has m lines. The i-th line should contain the pretty value of the dog who got the food in the i-th feeding.

Sample Input

7 21 5 2 6 3 7 41 5 32 7 1

Sample Output

32

Source

,zgl & twb

 

区间求第k大值。

treap树维护第k大值。

用类似莫队的方法,将区间排序,每次添加新进区间的数,删去已经出区间的数,然后在树上找第k大数。

 

1 /*by SilverN*/  2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 using namespace std; 10 const int mxn=100100; 11 int read(){ 12 int x=0,f=1;char ch=getchar(); 13 while(ch<'0' || ch>'9'){ if(ch=='-')f=-1;ch=getchar();} 14 while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();} 15 return x*f; 16 } 17 struct qry{ 18 int l,r; 19 int rk,id; 20 }a[mxn]; 21 int ans[mxn]; 22 int cmp(const qry q,const qry e){ 23 if(q.l!=e.l)return q.l
t[rt].v){ 65 insert(t[rt].r,x); 66 if(t[t[rt].r].rand
1){t[rt].size--;t[rt].ct--;return;} 78 if(t[rt].l*t[rt].r==0)rt=t[rt].l+t[rt].r;//子树补位 79 else{ 80 if(t[t[rt].l].rand
t[rt].v)del(t[rt].r,x); 93 if(x
t[t[rt].l].size+t[rt].ct)return query(t[rt].r,rank-t[t[rt].l].size-t[rt].ct);100 return t[rt].v;101 }102 //103 int n,m;104 int pt[mxn];105 106 int main(){107 t[0].size=0;108 a[0].l=1;a[0].r=0;109 srand(time(0));110 n=read();m=read();111 int i,j;112 for(i=1;i<=n;i++)pt[i]=read();113 for(i=1;i<=m;i++){a[i].l=read();a[i].r=read();a[i].rk=read();a[i].id=i;}114 sort(a+1,a+m+1,cmp);115 for(i=1;i<=m;i++){116 if(a[i].l>a[i-1].r){117 root=0;118 for(j=a[i].l;j<=a[i].r;j++)insert(root,pt[j]);119 }120 else{121 for(j=a[i-1].l;j

 

转载于:https://www.cnblogs.com/SilverNebula/p/5931461.html

你可能感兴趣的文章
python3的zip函数
查看>>
Paxos算法详细图解
查看>>
如何用Exchange Server 2003 构建多域名邮件系统
查看>>
httpd服务如何开机启动
查看>>
JAVA帮助文档全系列 JDK1.5 JDK1.6 JDK1.7 官方中英完整版下载
查看>>
android 1.6中LinearLayout getBaseline函数的一个bug
查看>>
shell3
查看>>
分享几个好用的工具,有效提升工作效率
查看>>
论北京北漂的家人们
查看>>
delphi 检查用户输入必须是汉字串
查看>>
思科交换机和路由器设备实现DHCP功能
查看>>
MongoDB安装与操作大全
查看>>
人我的是好有是的好sula
查看>>
编译工程时报java:[1,0] illegal character: \65279问题排查与解决过
查看>>
RHEL6子接口及双网卡绑定配置
查看>>
常见系统故障排查
查看>>
正则验证手机号是否合法
查看>>
《Git权威指南》读书笔记 第四章 git初始化
查看>>
《Head first HTML与CSS 第二版》读书笔记 第九章 盒模型
查看>>
《Python面向对象……》之目录
查看>>