#P2824. [HEOI2016/TJOI2016] 排序

    ID: 1880 远端评测题 4000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2016线段树二分各省省选河北排序

[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 11 to nn, perform mm local sorts on this sequence. There are two types of sorts:

  • 0 l r means sorting the numbers in the interval [l,r][l,r] in ascending order.
  • 1 l r means sorting the numbers in the interval [l,r][l,r] in descending order.

Note that this sorts the numbers whose indices lie in the interval [l,r][l,r].
Finally, query the number at position qq.

Input Format

The first line contains two integers nn and mm, where nn is the length of the sequence and mm is the number of local sorts.

The second line contains nn integers, representing a permutation of 11 to nn.

The next mm lines each contain three integers op,l,r\text{op}, l, r, where op\text{op} being 00 means ascending sort, op\text{op} being 11 means descending sort, and l,rl, r specify the interval to sort.

Finally, an integer qq 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 qq 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 30%30\% of the testdata, n,m1000n, m \leq 1000.

For 100%100\% of the testdata, n,m105n, m \leq 10^5, 1qn1 \leq q \leq n.

Translated by ChatGPT 5