RoAlgo Contest #4 (incepatori) | chmax

This was the problem page during the contest. Access the current page here.
Time limit: 0.6s Memory limit: 64MB Input: Output:

Raul and Deniz are playing True or False. Being computer scientists, they changed the game's settings, and now the questions are different. The game now proceeds as follows:

  1. Raul and Deniz receive the numbers NN, QQ, and a sequence a1 a2  aNa_1 \ a_2 \ \dots \ a_N of natural numbers.
  2. There are QQ questions of the form: "Given the numbers ll, rr, and pp (1lprN1 \leq l \leq p \leq r \leq N). Tell if apa_p is equal to max(al,al+1ar)max(a_l, a_{l+1} \dots a_r)". Raul and Deniz need to quickly determine if they should say True or False.

Task

To answer these questions very quickly, they asked you to help write a program that responds as quickly as possible to these queries.

Input data

The first line contains two natural numbers, NN and QQ.

The second line contains NN natural numbers, representing the sequence a1 a2  aNa_1 \ a_2 \ \dots \ a_N.

The next QQ lines each contain a triplet of numbers, representing ll, rr, and pp in this order.

Output data

Print a sequence of QQ characters, with the ii-th character being 11 if the answer to the ii-th query is true, and 00 otherwise.

Constraints and clarifications

  • 1N,Q1061 \leq N, Q \leq 10^6
  • ai109a_i \leq 10^9
  • It is recommended to print the entire sequence of characters (00 or 11) once, at the end of the queries
# Points Constraints
1 12 1N,Q3 0001 \leq N, Q \leq 3 \ 000
2 15 1N3 0001 \leq N \leq 3 \ 000
3 11 1N,Q100 0001 \leq N, Q \leq 100 \ 000
4 62 No other constraints

Example 1

stdin

8 12
1 5 5 2 4 9 3 2
1 2 2
1 2 1
2 3 2
2 3 2
2 4 3
2 4 4
2 4 2
1 6 6
7 8 8
4 5 4
3 6 3
3 6 6

stdout

101110110001

Explanation

N=8N = 8, Q=12Q = 12

a=[1,5,5,2,4,9,3,2]a = [1, 5, 5, 2, 4, 9, 3, 2]

The answer to the first query is true because l=1l = 1, r=2r = 2, p=2p = 2, ap=5a_p = 5, and max(a1,a2)=max(1,5)=5max(a_1, a_2) = max(1, 5) = 5. So, a2=max(a1,a2)a_2 = max(a_1, a_2). Therefore, the character to be printed is 11.

The answer to the second query is false because l=1l = 1, r=2r = 2, p=1p = 1, ap=1a_p = 1, but max(a1,a2)=5a1max(a_1, a_2) = 5 \neq a_1. Therefore, the character to be printed is 00.

The answer to the fifth query is true because l=2l = 2, r=4r = 4, p=3p = 3, and ap=a3=max(a2,a3,a4)=max(5,5,2)=5a_p = a_3 = max(a_2, a_3, a_4) = max(5, 5, 2) = 5. Therefore, the character to be printed at the fifth position is 11.

Log in or sign up to be able to send submissions!