Nice Queries
Practice
3.2 (19 votes)
Data structures
Hash maps
Hash tables
Medium
Problem
57% Success 6102 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given an array A of length N which is initialised with 0. You will be given Q queries of two types:

\(1\;k\): set value 1 at index k in array A

\(2\;y\): print the smallest index x which is greater than or equal to y and having value 1. If there is no such index print 1.

Note: Indexing is 1 based

Input Format

First line contains two integers N and Q separated by a space.

The next Q lines contain the type of query (i.e. either a 1 or a 2), then a space, then for type 1 queries integer k and for type 2 queries integer y

Output Format

For each query type 2, print in new line, the smallest index x which is greater than or equal to y and having value 1. If there is no such index print 1.

Constraints
\(1 \le n \le 10^{9}\)
\(1 \le q \le 5 * 10^{5}\)
\(1 \le y,k \le n\)

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
3 votes
Tags:
Data StructuresBasics of Hash TablesHash TablesHashmap
Points:30
21 votes
Tags:
Data StructuresBasics of Hash TablesHash TablesHashmap
Points:30
48 votes
Tags:
Ad-HocAlgorithmsApprovedHash MapsMediumOpen