SDNU 1429.区间k大数查询(水题)
生活随笔
收集整理的這篇文章主要介紹了
SDNU 1429.区间k大数查询(水题)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Description
問題描述 給定一個(gè)序列,每次詢問序列中第l個(gè)數(shù)到第r個(gè)數(shù)中第K大的數(shù)是哪個(gè)。Input
輸入格式 第一行包含一個(gè)數(shù)n,表示序列長度。 第二行包含n個(gè)正整數(shù),表示給定的序列。 第三個(gè)包含一個(gè)正整數(shù)m,表示詢問個(gè)數(shù)。 接下來m行,每行三個(gè)數(shù)l,r,K,表示詢問序列從左往右第l個(gè)數(shù)到第r個(gè)數(shù)中,從大往小第K大的數(shù)是哪個(gè)。序列元素從1開始標(biāo)號(hào)。Output
輸出格式 總共輸出m行,每行一個(gè)數(shù),表示詢問的答案。Sample Input
樣例輸入 5 1 2 3 4 5 2 1 5 2 2 3 2Sample Output
樣例輸出 4 2Hint
數(shù)據(jù)規(guī)模與約定 對(duì)于30%的數(shù)據(jù),n,m< =100; 對(duì)于100%的數(shù)據(jù),n,m< =1000; 保證k< =(r-l+1),序列中的數(shù)< =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\n", buffer[k-1]);}return 0; }?
轉(zhuǎn)載于:https://www.cnblogs.com/RootVount/p/11251436.html
總結(jié)
以上是生活随笔為你收集整理的SDNU 1429.区间k大数查询(水题)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 1452.接水问题(思维)
- 下一篇: SDNU 1427.分解质因数(水题)