# Algorithm training interval k large number query

Source: Internet
Author: User

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

Related Keywords:

### Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.