Problem 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.
Import Java.io.BufferedReader; Import java.io.IOException; Import java.io.inputstreamreader;import java.text.decimalformat;import java.util.*;p ublic class Main {public static void Main (string[] args) throws ioexception{ Scanner in= new Scanner (system.in); int N=in.nextint (); int []a=new int[n]; for (int i=0;i<n;i++) { a[i]=in.nextint (); } int M=in.nextint (); while (m>0) { int a1=in.nextint (); int A2=in.nextint (); int K=in.nextint (); int length=a2-a1+1; Int[]b =new Int[length]; for (int i=a1;i<=a2;i++) { b[i-a1]=a[i-1]; } Arrays.sort (b); System.out.println (B[length-k]); m--;}}}
Algorithm training interval k large number query