atcoder#ABC237G. [ABC237G] Range Sort Query
[ABC237G] Range Sort Query
Score : points
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.
5 2 1
1 4 5 2 3
1 3 5
2 1 3
3
Initially, the permutation is . The queries change it as follows.
- -st query sorts the -rd through -th elements in ascending order, making .
- -nd query sorts the -st through -rd elements in descending order, making .
In the final permutation, we have , so should be printed.
7 3 3
7 5 3 1 2 4 6
1 1 7
2 3 6
2 5 7
7
The final permutation is .