#P2824. [HEOI2016/TJOI2016] 排序
[HEOI2016/TJOI2016] 排序
Description
In 2016, sister Jiayuan became fond of number sequences. She often studies various quirky problems about sequences, and now she is working on a hard one that needs your help.
The problem is as follows: given a permutation of to , perform local sorts on this sequence. There are two types of sorts:
0 l rmeans sorting the numbers in the interval in ascending order.1 l rmeans sorting the numbers in the interval in descending order.
Note that this sorts the numbers whose indices lie in the interval .
Finally, query the number at position .
Input Format
The first line contains two integers and , where is the length of the sequence and is the number of local sorts.
The second line contains integers, representing a permutation of to .
The next lines each contain three integers , where being means ascending sort, being means descending sort, and specify the interval to sort.
Finally, an integer is given, indicating the position to query after all sorts are finished.
Output Format
Output a single line containing one integer, the number at position after performing all local sorts in order.
6 3
1 6 2 5 3 4
0 1 4
1 3 6
0 2 4
3
5
Hint
Hebei NOI Qualifier 2016 Day 1 Problem 2.
For of the testdata, .
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号