Blue Bridge Cup algorithm to train large numbers query interval k ALGO-1

Blue Bridge Cup algorithm to train large numbers query interval k ALGO-1

Resource constraints

Time limit: 1.0s Memory Limit: 256.0MB

Problem Description

Given a sequence, each query sequence number to the number of the l-r large number of which K.

Input Format

The first line contains a number n, the sequence length.
The second line contains n positive integer representing a given sequence.
The third contains a positive integer m, the number indicating an inquiry.
Next m lines of three numbers l, r, K, from left to right represents the query sequence to the number of the l-r in number, from large to small number of large K is which. Reference numeral sequence elements from the beginning.

Output Format

Total output m lines, each a number representing the answer to the inquiry.

Sample input

5
1 2 3 4 5
2
1 5 2
2 3 2

Sample Output

4
2

Data size and convention

For 30% of the data, n, m <= 100;
to 100% of the data, n, m <= 1000;
guaranteed k <= (r-l + 1), the sequence number <= 106.

#include <iostream>
#include <algorithm>
using namespace std;
bool cmp(int a,int b){
    return a > b ? true : false;
}
int main(){
    int n,m;
    int store[10005] = {0};
    cin>>n;
    for (int i = 1; i <= n; ++i) {
        cin>> store[i];
    }
    cin>>m;
    for (int i = 0; i < m; ++i) {
        int l,r,k;
        cin>>l>>r>>k;
        int temp[1005];
        int flag = 0;
        for (int j = l; j <= r; ++j)
            temp[flag++] = store[j];
        sort(temp,temp+(r-l+1),cmp);
        cout<<temp[k-1]<<endl;
    }
    return 0;
}
Published 139 original articles · won praise 67 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_43422111/article/details/104768474