SDNU 1429.区间k大数查询(水题)

Description

问题描述 给定一个序列,每次询问序列中第l个数到第r个数中第K大的数是哪个。

Input

输入格式 第一行包含一个数n,表示序列长度。 第二行包含n个正整数,表示给定的序列。 第三个包含一个正整数m,表示询问个数。 接下来m行,每行三个数l,r,K,表示询问序列从左往右第l个数到第r个数中,从大往小第K大的数是哪个。序列元素从1开始标号。

Output

输出格式 总共输出m行,每行一个数,表示询问的答案。

Sample Input

样例输入 
5 
1  2  3  4  5 
2 
1  5  2
2  3  2 

Sample Output

样例输出
4
2 

Hint

数据规模与约定 对于30%的数据,n,m< =100; 对于100%的数据,n,m< =1000; 保证k< =(r-l+1),序列中的数< =10^6。
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
using namespace std;
#define ll long long
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;

int n, a[1000+8], m, l, r, k, buffer[1000+8];

int main()
{
    scanf("%d", &n);
    for(int i = 0; i<n; i++)
        scanf("%d", &a[i]);
    scanf("%d", &m);
    for(int i = 0; i<m; i++)
    {
        scanf("%d%d%d", &l, &r, &k);
        int id = 0;
        for(int j = l-1; j<r; j++)
        {
            buffer[id++] = a[j];
        }
        sort(buffer, buffer+id, greater<int>());
        printf("%d
", buffer[k-1]);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/RootVount/p/11251436.html