#abc237g. [abc237_g]Range Sort Query
[abc237_g]Range Sort Query
Problem Statement
Given is a permutation of , and an integer .
Additionally, queries are given. The -th query is represented as a triple of numbers . Each query does the following operation on the permutation .
- If : sort in ascending order.
- If : sort in descending order.
In the final permutation after executing all queries in the given order, find such that .
Constraints
- is a permutation of .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
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.
- -st query sorts the -rd through -th elements in ascending order, making P=\[1,4,2,3,5\].
- -nd query sorts the -st through -rd elements in descending order, making P=\[4,2,1,3,5\].
In the final permutation, we have , so 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\].