POJ 2761 Feed the dogs

[统计] poj 2761 Feed the dogs /** [统计] poj 2761 Feed the dogs 题意: n个数,m个查询,每次查询[l,r]区间里第k小的数。(需要离散化) 题目保证了区间不会相互包含,可以按L排个序。 然后对于每个区间加入新节点,删去旧结点,就成了裸的查第k小。 这里用 树状数组+二分 实现,O(NlogNlogN) */ #include #include #include using namespac 阅读详情
Feed the dogs
Time Limit: 6000MS Memory Limit: 65536K
Total Submissions: 15298 Accepted: 4715

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 2
1 5 2 6 3 7 4
1 5 3
2 7 1

Sample Output

3
2

Source

解题思路:划分树模板题
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int Maxn=100010;
int tree[20][Maxn];
int sorted[Maxn];
int toleft[20][Maxn];
void build(int l,int r,int dep)
{
	if(l==r)
		return ;
	int mid=(l+r)>>1;
	int same=mid-l+1;
	for(int i=l;i<=r;i++)
		if(tree[dep][i]<sorted[mid])
			same--;
	int lpos=l;
	int rpos=mid+1;
	for(int i=l;i<=r;i++)
	{
		if(tree[dep][i]<sorted[mid])
			tree[dep+1][lpos++]=tree[dep][i];
		else if(tree[dep][i]==sorted[mid]&&same>0)
			tree[dep+1][lpos++]=tree[dep][i],same--;
		else
			tree[dep+1][rpos++]=tree[dep][i];
		toleft[dep][i]=toleft[dep][l-1]+lpos-l;
	}
	build(l,mid,dep+1);
	build(mid+1,r,dep+1);
}
int query(int L,int R,int l,int r,int dep,int k)
{
	if(l==r)
		return tree[dep][l];
	int mid=(L+R)>>1;
	int cnt=toleft[dep][r]-toleft[dep][l-1];
	if(cnt>=k)
	{
		int newl=L+toleft[dep][l-1]-toleft[dep][L-1];
		int newr=newl+cnt-1;
		return query(L,mid,newl,newr,dep+1,k);
	}
	else
	{
		int newr=r+toleft[dep][R]-toleft[dep][r];
		int newl=newr-(r-l-cnt);
		return query(mid+1,R,newl,newr,dep+1,k-cnt);
	}
}
int main()
{
	int n,m;
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	while(~scanf("%d%d",&n,&m))
	{
		memset(tree,0,sizeof(tree));
		for(int i=1;i<=n;i++)
			scanf("%d",&tree[0][i]),sorted[i]=tree[0][i];
		sort(sorted+1,sorted+1+n);
		build(1,n,0);
		while(m--)
		{
			int l,r,k;
			scanf("%d%d%d",&l,&r,&k);
			printf("%d\n",query(1,n,l,r,0,k));
		}
	}
	return 0;
}


FPGA网络调试实战:基于88E1111和DP83867两款PHY芯片的SGMII-UDP数据回环对比与避坑指南 本文深入对比了88E1111与DP83867两款PHY芯片在SGMII-UDP数据回环中的性能差异,涵盖硬件设计、Vivado工程配置及调试技巧。通过实测数据揭示DP83867在吞吐量、延迟和功耗方面的优势,并提供FPGA网络调试中的常见问题解决方案,助力工程师高效完成项目开发。 阅读详情

相关推荐

【Origin+Python】使用External Python批量出图代码参考2

不使用part2 的代码,自己打开一个origin2022的界面。这里主要介绍一些进阶代码以及使用盗版origin要如何。3 批量绘制相同设置的曲线图。然后就是没有水印的图片了。

zeng001201的博客 1912

poj2761——Feed the dogs(划分树或SBT)

Feed the dogs Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 13221Accepted: 3959 Description Wind loves pretty dogs very much, and she has n pet dogs. So Jiajia has to feed the dog

JIA_char 678

Unity Shader实战:用Matcap给你的低模角色快速换上‘次世代’材质(附完整Shader代码)

本文详细介绍了Unity中Matcap技术的实战应用,通过Shader代码实现低模角色的次世代材质表现。Matcap技术利用预烘焙光照贴图,显著提升材质质感同时保持极低性能消耗,特别适合移动游戏和独立开发。文章包含完整Shader代码、平面模型着色优化方案及动态环境反射增强技巧,帮助开发者快速提升低模视觉效果。

weixin_28718755的博客 393

poj2761(静态区间第k大,treap)

题意:给你一个序列和m个区间[l,r],每次输出每个区间中第k大的值为多少。区间之间有重叠但没有完全包含。 解析:由于区间没有完全包含。所以先将区间按左端点排序,每次查询一个新区间时将其与上一个区间重叠部分保留,其余删去,在加入自己新的部分,最后查询第k大值。这是一道考察treap应用的好题。 #include #include #include #include using namespac

xffyjq的博客 588

AICodeing:AI驱动的全栈开发革命

作为阿里/字节跳动的资深Java工程师,我们正站在研发效能革命的临界点上。本文将深入探讨如何利用AI技术重构全栈开发流程,实现从需求到上线的量子级提速。

weixin_43290370的博客 1145

移动端UI自动化测试新框架Maestro:声明式语法与实战指南

UI自动化测试是保障移动应用质量的关键环节,其核心原理是通过脚本模拟用户操作,对应用界面进行自动验证。传统命令式框架(如基于Selenium WebDriver的Appium)虽然控制粒度细,但脚本编写和维护成本较高。声明式测试框架则通过描述“做什么”而非“怎么做”,显著降低了技术门槛和维护复杂度,其技术价值在于提升测试脚本的可读性、编写效率与跨团队协作能力。在移动端测试领域,这尤其适用于需要快速验证核心业务流程、进行冒烟测试和回归测试的场景。本文聚焦的**Maestro框架**,正是这一理念的杰出实践。它

weixin_32921023的博客 719

POJ 2761 树状数组离线+离散化 附:线段树解法

#include #include #include #include #include #include #include #include #include #include using namespace std; const int N=100009; c

Join Hands 1220

使用 DeepSeek 配合 即梦AI 生成视频的详细教程

访问即梦AI官网,选择“AI作图”功能,将DeepSeek生成的提示词逐条粘贴至输入框,选择适配的模型(如“通用XL Pro”)和参数(如画幅比例、风格强度)1113。“我要制作一个关于普洱茶文化的宣传视频,请设计一个30秒的脚本,包含时间轴、画面描述、文案和分镜提示词,以表格形式输出。:云南古茶树群,清晨薄雾,金色晨光,露珠特写,国风山水画质感,16:9画幅,使用Nikon D850参数模拟513。:结合DeepSeek生成的知识点脚本与即梦AI的插画风格,制作科普动画211。

weixin_48995695的博客 3万+

poj2761----树状数组

简单的树状数组,复杂度是O(n+m)logn #include #include #include using namespace std; #define maxn 100005 #define maxm 50005 int cal[maxn],ans[maxn],sum[maxm],mid[maxn]; int n,m; struct TNode { int l,r,k,id; }nod[

carter91620 1804

Xilinx Chip2Chip IP核实战:Aurora PHY通信配置与仿真避坑指南

本文深入解析Xilinx Chip2Chip IP核与Aurora PHY的通信配置与仿真优化,提供实战避坑指南。通过AXI协议转换桥实现FPGA间高速数据传输,详细讲解Aurora PHY参数设置、仿真加速技巧及常见问题解决方案,帮助工程师快速部署稳定高效的芯片间通信系统。

g5h6i7j的博客 1010

软考嵌入式 第五讲 嵌入式Linux系统技术

5.1 inittab配置文件 Linux实时操作系统开机引导时首先启动内核,由内核检查和初始化硬件设备,载入设备的驱动程序模块,安装root文件系统,然后内核将启动一个名为init的进程,它是系统运行的第一个进程,进程号为1。在init运行完成并启动其他必要的后续进程后,系统开始运行,引导过程结束。 在任何时候,可以在文件inittab中添加新的记录项。重新检查inittab文件时,可以通过命令:init q/ Q使init进程立即重新读取并处理文件inittab。 5.1.1 inittab文件记录

Leon的博客 527

poj 2761 splay tree

这道题 可以用很多方法做像划分树之类滴~~~ 用splay虽然比划分树慢了一点,不过也只是慢了一点呀,想想有通用的解法,何必用不太常用的划分树喃~~ #include #include #include #include #define fr(i,s,n) for(int i=s;i<n;++i) #define _fr(i,n,s) for(int i=n-1;i>=s;

work_freedom的专栏 553

辉芒微教程第七篇《PWM与PWM3调节LED灯的亮度》

这个其实就是PR3L = 128设置的,由于我们刚刚寄存器设置了8位模式,其设置的范围就是0-255,而128/255≈50%左右,因此PR3L就是我们的占空比调节的寄存器,我们可以通过它来调节占空比,大家可以试试它占空比设置10%,30%,60%来看看它的不同效果,灯的亮度是肯定不一样的,如果有条件的朋友,可以购买一款逻辑分析仪去看他的占空比。平平无期的这个东西有什么东东用,貌似是没什么用,只是一个概念而已,是不是不同设备可以设置1秒,3秒,10秒的周期就行?但是它占空比为什么是50%,怎么得来的?

qq_41809823的博客 838

poj2761 Feed the dogs

Treap模板题

AaronPolaris 1906

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

poj2761 Feed the dogs【解法一】

离散化+树状数组+二分

YHaX的博客 664

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

poj 2761 Feed the dogs

题意:给出n( 解:因为两两查询区间互不包含,所以按L从小到大排序,则必有Li       所以对于每一个查询,删除当前treap中当前查询不包含的点,插入当前treap中当前查询未插入的点       每个点删,插各一次,用treap实现,所以时间复杂度为O(nlogn) 代码: #include #include #include #include #include #d

ba1_1ad的博客 463

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

POJ2761 Feed the dogs

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 t...

dezhen7015的博客 152

poj 2761 Feed the dogs

Treap

GadyPu的专栏 349

poj2761 Feed the dogs【解法二】

离散化+线段树

YHaX的博客 479

[SBT]POJ 2761 Feed the dogs

题目链接:http://poj.org/problem?id=2761 题意:给定一个序列,有N个数,给定M个询问,询问的形式为 a b c ,询问区间[a,b]内第c小的数。 解题方法:一次性读入所有的询问,然后把询问进行排序,排序的顺序为终点小的在前,终点一样,起点大的在前,然后对排序后的每个询问进行处理,每次保证SBT中只有区间[a,b]的数(用插入和删除操作来保证),然后查询第K小。

Airarts_的专栏 877

[POJ2761]Feed the dogs

Problem 查询区间第k大,但保证区间不互相包含(可以相交) Solution 只需要对每个区间左端点进行排序,那它们的右端点必定单调递增,不然会出现区间包含的情况。 所以我们暴力对下一个区间加上这个区间没有的点,删去下个区间没有的点。 因为每个点最多被加入,删除1次,所以时间复杂度为O(nlogn) Notice 当相邻两段区间不相交时,那么我们要先加入点,在删去点。 Code 非...

Q882199的博客 202

POJ2761 Feed the dogs(Treap)

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 ...

邵光亮的博客 315

[poj2761]Feed the dogs

treap 区间第k大

hccz95的专栏 1083

POJ2761 Feed the dogs(treap)

Feed the dogs Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 21225   Accepted: 6719 Description Wind loves pretty dogs very much, and she has n pet dogs.

HOrchard 392

【poj2761】 Feed the dogs

http://poj.org/problem?id=2761 (题目链接)题意:求区间第K大。Solution   和poj2104一模一样。主席树代码:// poj2761 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #include<cmath> #def

MashiroSky的博客 376
上一篇: HDU 3473 Minimum Sum
下一篇: HDU 2492 Ping pong
hqu_fritz
博客等级 码龄14年 69粉丝 231原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值