Algorithm training interval k large number query time limit: 1.0s memory limit: 256.0MBProblem description
Given a sequence, the number of the number L to the r number in each query sequence is the first.
Input format
The first row contains a number n, which represents the sequence length.
The second row contains n positive integers that represent the given sequence.
The third consists of a positive integer m, which indicates the number of queries.
The next m line, three numbers per line l,r,k, indicates the question sequence from left to right the number of R number, from the big to the small K large number is which. Sequence elements are labeled starting from 1.
The output format outputs a total of M rows, one number per line, indicating the answer to the query. Sample Input 5
1 2 3) 4 5
2
1 5 2
2 3 2 Sample output 4
2 Data size and conventions
For 30% of data,n,m<=100;
For 100% of data,n,m<=1000;
Guaranteed k<= (r-l+1), number <=106 in the sequence.
#include <iostream>#include<cstdio>#include<algorithm>#include<cstdlib>#definefor (i,x,n) for (int i=x;i<n;i++)using namespacestd;intMain () {intn,m,l,r,k; inta[1111]; intt[1111]; scanf ("%d",&N); forI1, n+1) {scanf ("%d",&A[i]); T[i]=A[i]; } scanf ("%d",&m); for(J,0, M) {scanf (" %d%d%d",&l,&r,&k); Sort (a+l,a+r+1); printf ("%d\n", a[r-k+1]); for(i,l,r+1) {A[i]=T[i]; } } return 0;}
Algorithm training interval k large number query