#abc324g. G - Generate Arrays
G - Generate Arrays
Score : points
问题描述
Takahashi 拥有一条长度为 的序列:。序列 是 的一个排列。
他打算执行 次操作以创建 条序列。他将序列 编号为 ,然后开始一系列操作。第 次操作()由三个整数 表示,并对应以下操作(参见样例输入/输出中的解释):
- 当 时,他从编号为 ()的序列中移除第 个元素之后的所有元素,并保持移除元素的顺序,用这些元素创建一个新的编号为 的序列。
- 当 时,他从编号为 ()的序列中移除所有大于 的元素,并保持移除元素的顺序,用这些元素创建一个新的编号为 的序列。
对于长度为 的序列 ,其每个元素都是“紧跟在第 个元素之后”的元素之一。另外,对于任何满足 的 ,序列 中的元素都不属于“紧跟在第 个元素之后”的元素。
对于 ,请找出在第 次操作 完成后立即 编号为 的序列的长度。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi has a sequence of length : . is a permutation of .
He is going to perform operations to create sequences. He lets be the sequence numbered , and then begins the series of operations. The -th operation is represented by a triple of integers and corresponds to the following operation (see also the explanations in Sample Input/Output).
- When , he removes the elements following the -th element from the sequence numbered , and creates a new sequence numbered with the removed elements, keeping their order.
- When , he removes the elements greater than from the sequence numbered , and creates a new sequence numbered with the removed elements, keeping their order.
For a sequence of length , every element of is among "the elements following the -th element." Also, for any such that , no element of is among "the elements following the -th element."
For , find the length of the sequence numbered immediately after the -th operation.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the length of the sequence numbered immediately after the -th operation.
Sample Input 1
10
1 8 7 4 5 6 3 2 9 10
5
2 0 4
1 1 2
2 0 2
2 2 5
1 0 1
Sample Output 1
6
4
2
3
1
Initially, Takahashi has a sequence of length . He lets be the sequence numbered , and then begins the series of operations.
In the first operation, he removes elements greater than from the sequence numbered , namely , and creates a new sequence numbered with these elements. After this operation, the sequences numbered and are and , respectively.
In the second operation, he removes the elements following the -nd element from the sequence numbered , namely , and creates a new sequence numbered with these elements. After this operation, the sequences numbered , , and are , , and , respectively.
For the third and subsequent operations, the sequences numbered after the -th operation are as follows:
The length of the sequence numbered after the -th operation for is . Print each of these in its own line.
Sample Input 2
8
6 7 8 4 5 1 3 2
5
2 0 0
1 1 0
2 2 0
1 3 8
2 2 3
Sample Output 2
8
8
8
0
0
The operations may create empty sequences.
Sample Input 3
30
20 6 13 11 29 30 9 10 16 5 8 25 1 19 12 18 7 2 4 27 3 22 23 24 28 21 14 26 15 17
10
1 0 22
1 0 21
2 0 15
1 0 9
1 3 6
2 3 18
1 6 2
1 0 1
2 5 20
2 7 26
Sample Output 3
8
1
8
4
2
5
3
8
1
1
update @ 2024/3/10 01:47:09