#abc237g. G - Range Sort Query
G - Range Sort Query
Score : points
问题描述
给定一个由 构成的排列 ,以及一个整数 。
另外,还给出了 个查询。第 个查询表示为一个三元组 。每个查询对排列 执行以下操作:
- 若 :将 按升序排序。
- 若 :将 按降序排序。
在按照给定顺序执行完所有查询之后,在最终的排列 中找到满足 的 。
以上为通义千问 qwen-max 翻译,仅供参考。
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 . 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.
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 .
update @ 2024/3/10 10:16:27