#P9995. [Ynoi2000] rspcn

[Ynoi2000] rspcn

Problem Description

Given an integer sequence a1,,ana_1,\dots,a_n, there are mm operations in total.

Each operation gives l,r,xl, r, x. First perform a modification, then query how many distinct values there are in a1,,axa_1,\dots,a_x.

If lrl \le r, the modification is to sort al,,ara_l,\dots,a_r in increasing order; otherwise, the modification is to sort ar,,ala_r,\dots,a_l in decreasing order.

Input Format

The first line contains two integers n,mn, m.

The second line contains nn integers a1,,ana_1,\dots,a_n.

The next mm lines each contain three integers lc,rc,xcl \oplus c, r \oplus c, x \oplus c, describing each operation in order, where \oplus is bitwise XOR, and cc is the answer to the previous operation’s query (in particular, for the first operation, c=0c = 0).

Output Format

Output mm lines, each containing one integer, in order, representing the answer to the query of each operation.

9 7
2 2 8 8 2 8 2 1 3
2 2 2
3 7 6
6 7 1
9 6 7
10 11 10
7 0 5
5 1 7
1
2
1
2
3
2
2

Hint

Idea: ccz181078, Solution: ccz181078, Code: ccz181078, Data: ccz181078.

Constraints:

For 20%20\% of the testdata, n,m103n, m \le 10^3.

For another 20%20\% of the testdata, ai10a_i \le 10.

For another 20%20\% of the testdata, ai100a_i \le 100.

For another 20%20\% of the testdata, n,m105n, m \le 10^5.

For 100%100\% of the testdata, 1ain1 \le a_i \le n, 1l,r,xn1 \le l, r, x \le n, and 1n,m1061 \le n, m \le 10^6.

Translated by ChatGPT 5