zoukankan      html  css  js  c++  java
  • 算法训练 区间k大数查询

      算法训练 区间k大数查询  
    时间限制:1.0s   内存限制:256.0MB
          
    问题描述

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

    输入格式

    第一行包含一个数n,表示序列长度。

    第二行包含n个正整数,表示给定的序列。

    第三个包含一个正整数m,表示询问个数。

    接下来m行,每行三个数l,r,K,表示询问序列从左往右第l个数到第r个数中,从大往小第K大的数是哪个。序列元素从1开始标号。

    输出格式
    总共输出m行,每行一个数,表示询问的答案。
    样例输入
    5
    1 2 3 4 5
    2
    1 5 2
    2 3 2
    样例输出
    4
    2
    数据规模与约定

    对于30%的数据,n,m<=100;

    对于100%的数据,n,m<=1000;

    保证k<=(r-l+1),序列中的数<=106。

    #include <cstdio>
    #include <iostream>
    #include <cstring>
    #include <string>
    #include <cmath>
    #include <algorithm>
    #include <queue>
    using namespace std;
    int arr[1005];
    int main()
    {
    int n, m, l, r, k;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    scanf("%d", &arr[i]);
    scanf("%d", &m);
    while(m--)
    {
    priority_queue<int> que;
    scanf("%d%d%d", &l, &r, &k);
    for(int i = l - 1; i < r; i++)
    que.push(arr[i]);
    while(--k)
    que.pop();
    printf("%d
    ", que.top());
    }
    return 0;
    }
  • 相关阅读:
    第八周总结和实验六
    第七周总结与实验五
    遍历目录中的所有文件和目录,并生成全路径
    python watchdog
    Offer_answer_with_SDP_rfc3264
    [转]UML八大误解
    leetcode周赛220
    Codeforces Round #690 (Div. 3)
    学习资料
    鱼眼图与六面图转换(python)
  • 原文地址:https://www.cnblogs.com/watchfree/p/5344551.html
Copyright © 2011-2022 走看看