Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

*Tasnim Imran Sunny is the fifth Bangladeshi red coder from Topcoder. This problem is to pay tribute to his unparalleled passion for problem solving.*

You will be given an array $A$ of $N$ integers. After that, you will be given some queries on the following format:

$a$ $b$ $x$

In each query, you will have to answer if there exists an integer $x$ from index $a$ to $b$ in the given array.

The first line of the input will have two integers $N$ and $Q$, where $N$ is the size of the array and $Q$ is the total number of queries.

Each of the next $N$ lines will have one integer $Ai$, indicating integer at the i’th position of array A.

Each of the following $Q$ lines will will be in the format a b x, where ( $0 <= a <= b < N$ ) and ( $0 <= x <= 10^9$ ).

Subtask 1 (10 points):

$1 <=$ Size of the array $<= 100$

$0 <=$ Value of each element $<= 100$

$1 <=$ Number of queries $<= 100$

Subtask 2 (20 points):

$1 <=$ Size of the array $<= 10^5$

$0 <=$ Value of each element $<= 100$

$1 <=$ Number of queries $<= 10^5$

Subtask 3 (30 points):

$1 <=$ Size of the array $<=$ $10^5$

$0 <=$ Value of each element $<= 10^5$

$1 <=$ Number of queries $<= 10^5$

Subtask 4 (40 points):

$1 <=$ Size of the array $<= 10^5$

$0 <=$ Value of each element $<= 10^5$

$1 <=$ Number of queries $<= 10^6$

For each query, please print “Yes” if x exists in each query or “No” otherwise.

Input | Output |
---|---|

3 1 1 2 3 0 2 3 | Yes |

59% Solution Ratio

Mr.HmianEarliest,

user.545264Fastest, 0.2s

user.545264Lightest, 8.8 MB

ITisMAHMUDShortest, 450B

Login to submit

This problem can be solved in a few ways: For easy sub-task, a simple for loop checking the query ...

Toph uses cookies. By continuing you agree to our Cookie Policy.