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.
Author idea: Input sequence (record the original order), enter the number of queries (that is, M in the title), the definition of int c[m]--used to record each answer, ready to output in the last branch; input L, R, K, note: No input set L, R, K remember to return the array to the original order.
1#include <stdio.h>2#include <algorithm>3 using namespacestd;4 BOOLcmpintAintb) {5 returnA>b;6 }7 8 intMain () {9 intN,m;//n denotes sequence length, number of queriesTen intL,r,k;//Indicates the number of numbers from the first l to the R number of the query sequence. Onescanf"%d",&N); A intA[n],b[n],f[n]; - for(intI=0; i<n;i++){ -scanf"%d",&a[i]); the /*record the original order*/ -F[i] =A[i]; - } - +scanf"%d",&m); - intC[m]; + for(ints=0; s<m;s++){ A /*input query sequence number from L to r number, K large*/ atscanf"%d%d%d", &l, &r, &K); - for(intj =0, i = l1; I < R; i++){ -B[j++] =A[i]; - } -Sort (b, b+r-l+1, CMP); - /*to put an answer on a condition in an array*/ inC[s] = b[k-1]; - /*a returns to the original order*/ to for(intI=0; i<n;i++){ +A[i] =F[i]; - } the //printf ("%d\n", C[m]); * } $ /*output answers on condition*/ Panax Notoginseng for(intj=0; j<m;j++){ -printf"%d\n", C[j]); the } +}
C language · Interval k Large number query