Blue Bridge Cup--algorithm training interval k large number query

Source: Internet
Author: User

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

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.