Fredo and Large Numbers
Practice
3.9 (42 votes)
Ad Hoc
Data structures
Easy
One Dimensional
Data compression
Problem
66% Success 22077 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Fredo is pretty good at dealing large numbers. So, once his friend Zeus gave him an array of N numbers , followed by Q queries which he has to answer. In each query , he defines the type of the query and the number f for which Fredo has to answer. Each query is of the following two types:
Type 0: For this query, Fredo has to answer the first number in the array (starting from index 0) such that its frequency is atleast equal to f.
Type 1: For this query, Fredo has to answer the first number in the array such that frequecy is exactly equal to f.
Now, Fredo answers all his queries but now Zeus imagines how he should verify them . So, he asks you to write a code for the same.
Note: If there is no number which is the answer to the query, output 0.
Use fast I/O.

Input :
The first line of the input contains N , the size of the array
The next line contains N space separated integers.
The next line contains Q, denoting the number of queries.
Then follow Q lines, each line having two integers type and f, denoting the type of query and the frequency for which you have to answer the query.

Output:
You have to print the answer for each query in a separate line.

Input Constraints:
\(1 \le N \le 10^6\)
\(1 \le A[i] \le 10^{18}\)
\(1 \le Q \le 10^6\)
\(0 \le type \le 1\)
\(1 \le f \le 10^{18}\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
31 votes
Tags:
Easy
Points:30
24 votes
Tags:
1-D ArrayArraysData Structures
Points:30
29 votes
Tags:
Basic ProgrammingData StructuresPrefixArraysBasics of Greedy Algorithms1-D