#abc237g. [abc237_g]Range Sort Query

[abc237_g]Range Sort Query

Problem Statement

Given is a permutation P=(P1,P2,ldots,PN)P=(P_1,P_2,\\ldots,P_N) of 1,2,ldots,N1,2,\\ldots,N, and an integer XX.

Additionally, QQ queries are given. The ii-th query is represented as a triple of numbers (Ci,Li,Ri)(C_i,L_i,R_i). Each query does the following operation on the permutation PP.

  • If Ci=1C_i=1: sort PLi,PLi+1,ldots,PRiP_{L_i},P_{L_i+1},\\ldots,P_{R_i} in ascending order.
  • If Ci=2C_i=2: sort PLi,PLi+1,ldots,PRiP_{L_i},P_{L_i+1},\\ldots,P_{R_i} in descending order.

In the final permutation PP after executing all queries in the given order, find ii such that Pi=XP_i=X.

Constraints

  • 1leqNleq2times1051 \\leq N \\leq 2\\times 10^5
  • 1leqQleq2times1051 \\leq Q \\leq 2\\times 10^5
  • 1leqXleqN1 \\leq X \\leq N
  • (P1,P2,ldots,PN)(P_1,P_2,\\ldots,P_N) is a permutation of (1,2,ldots,N)(1,2,\\ldots,N).
  • 1leqCileq21 \\leq C_i \\leq 2
  • 1leqLileqRileqN1 \\leq L_i \\leq R_i \\leq N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN QQ XX P1P_1 P2P_2 ldots\\ldots PNP_N C1C_1 L1L_1 R1R_1 C2C_2 L2L_2 R2R_2 vdots\\vdots CQC_Q LQL_Q RQR_Q

Output

Print the answer.


Sample Input 1

5 2 1
1 4 5 2 3
1 3 5
2 1 3

Sample Output 1

3

Initially, the permutation is P=\[1,4,5,2,3\]. The queries change it as follows.

  • 11-st query sorts the 33-rd through 55-th elements in ascending order, making P=\[1,4,2,3,5\].
  • 22-nd query sorts the 11-st through 33-rd elements in descending order, making P=\[4,2,1,3,5\].

In the final permutation, we have P3=1P_3=1, so 33 should be printed.


Sample Input 2

7 3 3
7 5 3 1 2 4 6
1 1 7
2 3 6
2 5 7

Sample Output 2

7

The final permutation is P=\[1,2,6,5,7,4,3\].