Title Description
In 2016, Jia Yuan sister liked the sequence of numbers.
Thus she often studies strange questions about some of the odd-odd sequence, and now she studies a problem, you need to help her.
This problem is like this: given a full array from 1 to n, the now full array partial sequence m times, the sort divided into two types: 1: (0, l, r) represents the interval [L, r] in ascending numerical order 2: (1, l, r) represents the interval [l, r] in descending order of the digital numbers on the last interrogation of the position q.
Input Format
Behavioral data input of the first two integers n and m. n represents the length of the sequence, m represents the number of partially ordered.
The second line n integer, n represents 1 to a full permutation.
Next, the input m rows, each row has three integers op, l, r, op is 0 for ascending order, for the OP represents descending order, l, r indicates the sort range.
Finally enter an integer q, q represents inquiry completion position after sorting.
Output Format
Output data of only one row, an integer indicating the order according to the end portions of all the first sort numbers on the position q.
Sample
Sample input
6 3
1 6 2 5 3 4
0 1 4
1 3 6
0 2 4
3
Sample Output
5
Data range and tips
$1\leqslant n,m\leqslant {10}^5$
$1\leqslant q\leqslant n$
answer
It is on the "do not fight positive solution for me," the plate, really, I played this question of violence.
First consider violent sort, the time complexity: $ \ Theta (n ^ 2 \ log n) $.
but