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 <=10 6 in the sequence.
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespacestd;intcmpintXinty) { returnX>y;}intMain () {intn,i,a[1005],m,l,r,k; scanf ("%d",&N); a[0]=0; for(i=1; i<=n;i++) scanf ("%d",&A[i]); scanf ("%d",&m); while(m--) { intb[1005]; scanf ("%d%d%d",&l,&r,&k); intx=0; for(i=l;i<=r;i++) B[x++]=A[i]; Sort (b,b+x,cmp); printf ("%d\n", b[k-1]); } return 0;}
Blue Bridge Cup--algorithm training interval k large number query