POJ 2371 Questions and answers

Source: Internet
Author: User

Description

The database of the Pentagon contains a top-secret information. we don't know what the information is-you know, it's top-secret,-but we know the format of its representation. it is extremely simple. we don't know why, but all the data is coded by the natural numbers from 1 up to 5000. the size of the main base (we'll denote it be N) is rather big-it may contain in up to 100 000 those numbers. th E database is to process quickly every query. The most often query is: "Which element is I-th by its value? "-With I being a natural number in a range from 1 to N.

Your program is to play a role of a controller of the database. In the other words, it shocould be able to process quickly queries like this.

Input

The standard input of the problem consists of two parts. at first, a database is written, and then there's a sequence of queries. the format of database is very simple: in the first line there's a number N, in the next N lines there are numbers of the database one in each line in an arbitrary order. A sequence of queries is written simply as well: in the first line of the sequence a number of queri Es K (1 <= K <= 100) is written, and in the next K lines there are queries one in each line. the query "Which element is I-th by its value? "Is coded by the number I. A database is separated from a sequence of queries by the string of three symbols "#".

Output

The output shoshould consist of K lines. in each line there shocould be an answer to the corresponding query. the answer to the query "I" is an element from the database, which is I-th by its value (in the order from the least up to the greatest element ).

Sample Input

571211237121 ### 43325

Sample Output

1211217123


It is to give you a set of numbers. The numbers are listed above, and the numbers are listed below.

1 # include <stdio. h> 2 int n, a [999999], B [999999]; 3 void kuaipai (int left, int right) 4 {5 int I, j, t, temp; 6 if (left> right) 7 return; 8 temp = a [left]; 9 I = left; 10 j = right; 11 while (I! = J) 12 {13 while (a [j]> = temp & I <j) 14 j --; 15 while (a [I] <= temp & I <j) 16 I ++; 17 if (I <j) 18 {19 t = a [I]; 20 a [I] = a [j]; 21 a [j] = t; 22} 23} 24 a [left] = a [I]; 25 a [I] = temp; 26 kuaipai (left, i-1); 27 kuaipai (I + 1, right); 28} 29 int main () 30 {31 while (scanf ("% d", & n )! = EOF) 32 {33 int I, j; 34 for (I = 1; I <= n; I ++) 35 {36 scanf ("% d ", & a [I]); 37} 38 kuaipai (1, n); 39 char s [1, 100]; 40 scanf ("% s", s ); 41 scanf ("% d", & n); 42 for (I = 1; I <= n; I ++) 43 scanf ("% d ", & B [I]); 44 for (I = 1; I <= n; I ++) 45 printf ("% d \ n ", a [B [I]); 46 47 48} 49 return 0; 50}
View Code

 

POJ 2371 Questions and answers

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.