poj-2104【构造】
来源:互联网 发布:淘宝 厂家投诉 编辑:程序博客网 时间:2024/06/09 18:47
题目链接:点击打开链接
K-th Number
Time Limit: 20000MS Memory Limit: 65536KTotal Submissions: 53943 Accepted: 18542Case Time Limit: 2000MS
Description
You are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structure that would be able to return quickly k-th order statistics in the array segment.
That is, given an array a[1...n] of different integer numbers, your program must answer a series of questions Q(i, j, k) in the form: "What would be the k-th number in a[i...j] segment, if this segment was sorted?"
For example, consider the array a = (1, 5, 2, 6, 3, 7, 4). Let the question be Q(2, 5, 3). The segment a[2...5] is (5, 2, 6, 3). If we sort this segment, we get (2, 3, 5, 6), the third number is 5, and therefore the answer to the question is 5.
That is, given an array a[1...n] of different integer numbers, your program must answer a series of questions Q(i, j, k) in the form: "What would be the k-th number in a[i...j] segment, if this segment was sorted?"
For example, consider the array a = (1, 5, 2, 6, 3, 7, 4). Let the question be Q(2, 5, 3). The segment a[2...5] is (5, 2, 6, 3). If we sort this segment, we get (2, 3, 5, 6), the third number is 5, and therefore the answer to the question is 5.
Input
The first line of the input file contains n --- the size of the array, and m --- the number of questions to answer (1 <= n <= 100 000, 1 <= m <= 5 000).
The second line contains n different integer numbers not exceeding 109 by their absolute values --- the array for which the answers should be given.
The following m lines contain question descriptions, each description consists of three numbers: i, j, and k (1 <= i <= j <= n, 1 <= k <= j - i + 1) and represents the question Q(i, j, k).
The second line contains n different integer numbers not exceeding 109 by their absolute values --- the array for which the answers should be given.
The following m lines contain question descriptions, each description consists of three numbers: i, j, and k (1 <= i <= j <= n, 1 <= k <= j - i + 1) and represents the question Q(i, j, k).
Output
For each question output the answer to it --- the k-th number in sorted a[i...j] segment.
Sample Input
7 31 5 2 6 3 7 42 5 34 4 11 7 3
Sample Output
563
Hint
This problem has huge input,so please use c-style input(scanf,printf),or you may got time limit exceed.
大意:给你含n个数的数组。然后叫你求 i,j 之间的第 k 大数。
#include<cstdio>#include<algorithm>#include<cstring>using namespace std;typedef pair<int,int> pii;pii a[100010];int n,m;int main(){while(~scanf("%d%d",&n,&m)){for(int i=1;i<=n;i++){scanf("%d",&a[i].first);a[i].second=i;}sort(a+1,a+n+1);while(m--){int l,r,k;scanf("%d%d%d",&l,&r,&k);int i=0,cnt=0;while(i<=n&&cnt<k){i++;if(a[i].second>=l&&a[i].second<=r)cnt++;}printf("%d\n",a[i].first);}}return 0; }
0 0
- poj-2104【构造】
- poj 1186 哈希表构造
- poj 3295 构造
- poj 2201 构造
- poj 2166 构造
- poj 1659 构造
- poj 2825 蜜汁构造
- poj 3295 构造法
- POJ 1305 勾股数的构造
- POJ 3295 Tautology 构造方法
- POJ 3735 构造矩阵乘法
- POJ 3420 构造矩阵乘法
- POJ-3735 线性变换构造矩阵
- POJ 1977 构造矩阵乘法
- 【Prim】-POJ-2421-构造公路
- POJ - 3295 - Tautology (构造)
- POJ 3295 Tautology 构造 stack
- [POJ 3295]Tautology[构造][DFS]
- 自动安装pkg的依赖包
- Android依赖管理与私服搭建
- ToolBar的再使用
- C#学习笔记(定义属性get&set)
- 教你快速认识mapreduce和hadoop
- poj-2104【构造】
- JAVA从键盘输入三种常规方法详解
- 回归问题中-梯度下降原理及思考
- 在vs2008中编写c控制台程序,运行完后经常一闪而过解决办法
- Python HackerRank|Piling Up!(from collections import deque)
- ueditor自定义上传
- MPU6050+HMC5883+BMP180+GPS导航系统设计
- 二叉树三种遍历递归及非递归实现
- Unity SLua+FairyGUI