#P9247. [集训队互测 2018] 完美的队列

[集训队互测 2018] 完美的队列

Problem Description

Xiao D has nn std::queue<int> objects, numbered from 11 to nn.

Xiao D has a different level of liking for each queue. If a queue that he does not like much uses too much memory, Xiao D will be unhappy.

More specifically, if the size() of the ii-th queue is greater than aia_i, Xiao D will keep calling pop() on this queue until its size() becomes less than or equal to aia_i.

Now all these queues are empty. Xiao D thinks this is too boring, so he decides to perform some operations.

Each operation can be described by l r x, meaning that for all queues with indices in [l,r][l, r], perform push(x). Of course, after each operation ends, Xiao D will use the method mentioned above to prevent these queues from using too much memory.

Xiao D's queues are magical, so he can perform each operation in O(1)O(1) time.

He believes everyone else's queues can do it too, so Xiao D made this problem to give everyone easy points.

To prove that you really performed these operations, after each operation you need to output the number of distinct values that are still present in the queues.

Input Format

The first line contains two positive integers n,mn, m, representing the number of queues and the number of operations.

The second line contains nn positive integers, where the ii-th one is aia_i.

The next mm lines each contain three positive integers l r x, where the ii-th line describes the ii-th operation.

Output Format

Output mm lines in total. Each line contains one non-negative integer, representing the number of distinct values across all queues after the ii-th operation ends.

3 3
1 2 3
1 2 1
2 3 2
1 3 3
1
2
2

Hint

Sample Explanation

After the first operation, the queues become {1}{1}{}\{1\}\{1\}\{\}, and the values still in the queues are 11, so there is 11 distinct value.

After the second operation, the queues become {1}{1,2}{2}\{1\}\{1,2\}\{2\}, and the values still in the queues are 1,21, 2, so there are 22 distinct values.

After the third operation, the queues become {3}{2,3}{2,3}\{3\}\{2,3\}\{2,3\}, and the values still in the queues are 2,32, 3, so there are 22 distinct values.

Constraints

For all data, n,m,ai,x105n, m, a_i, x \leq 10^5, and lrl \leq r.

There are 2020 test points in total, each worth 55 points. The kk-th test point satisfies n,m,ai,x5000kn, m, a_i, x \leq 5000k.

In particular, the following test points satisfy some special properties:

Test point 55: ai=1a_i = 1;
Test point 77: ai=2a_i = 2;
Test point 99: ai=10a_i = 10;
Test point 1111: ai10a_i \leq 10;
Test points 13,1513, 15: ai106\sum a_i \leq 10^6.

For each test point, you must pass all testdata that meets the constraints and properties of that point to obtain the score for that point.

Translated by ChatGPT 5