#abc324g. G - Generate Arrays

G - Generate Arrays

Score : 600600 points

问题描述

Takahashi 拥有一条长度为 NN 的序列:A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N)。序列 AA(1,2,,N)(1,2,\ldots,N) 的一个排列。

他打算执行 QQ 次操作以创建 1+Q1+Q 条序列。他将序列 AA 编号为 00,然后开始一系列操作。第 ii 次操作(1iQ1\leq i\leq Q)由三个整数 (ti,si,xi)(t_i,s_i,x_i) 表示,并对应以下操作(参见样例输入/输出中的解释):

  • ti=1t_i=1 时,他从编号为 sis_i0si<i0\leq s_i < i)的序列中移除第 xix_i 个元素之后的所有元素,并保持移除元素的顺序,用这些元素创建一个新的编号为 ii 的序列。
  • ti=2t_i=2 时,他从编号为 sis_i0si<i0\leq s_i < i)的序列中移除所有大于 xix_i 的元素,并保持移除元素的顺序,用这些元素创建一个新的编号为 ii 的序列。

对于长度为 LL 的序列 XX,其每个元素都是“紧跟在第 00 个元素之后”的元素之一。另外,对于任何满足 LlL\leq lll,序列 XX 中的元素都不属于“紧跟在第 ll 个元素之后”的元素。

对于 i=1,2,,Qi=1,2,\ldots,Q,请找出在第 ii 次操作 完成后立即 编号为 ii 的序列的长度。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Takahashi has a sequence of length NN: A=(A1,A2,,AN)A=(A _ 1,A _ 2,\ldots,A _ N). AA is a permutation of (1,2,,N)(1,2,\ldots,N).

He is going to perform QQ operations to create 1+Q1+Q sequences. He lets AA be the sequence numbered 00, and then begins the series of operations. The ii-th operation (1iQ)(1\leq i\leq Q) is represented by a triple of integers (ti,si,xi)(t _ i,s _ i,x _ i) and corresponds to the following operation (see also the explanations in Sample Input/Output).

  • When ti=1t _ i=1, he removes the elements following the xix _ i-th element from the sequence numbered sis _ i (0si<i)(0\leq s _ i\lt i), and creates a new sequence numbered ii with the removed elements, keeping their order.
  • When ti=2t _ i=2, he removes the elements greater than xix _ i from the sequence numbered sis _ i (0si<i)(0\leq s _ i\lt i), and creates a new sequence numbered ii with the removed elements, keeping their order.

For a sequence XX of length LL, every element of XX is among "the elements following the 00-th element." Also, for any ll such that LlL\leq l, no element of XX is among "the elements following the ll-th element."

For i=1,2,,Qi=1,2,\ldots,Q, find the length of the sequence numbered ii immediately after the ii-th operation.

Constraints

  • 1N2×1051\leq N\leq2\times10^5
  • 1AiN (1iN)1\leq A _ i\leq N\ (1\leq i\leq N)
  • AiAj (1i<jN)A _ i\neq A _ j\ (1\leq i\lt j\leq N)
  • 1Q2×1051\leq Q\leq2\times10^5
  • ti=1,2 (1iQ)t _ i=1,2\ (1\leq i\leq Q)
  • 0si<i (1iQ)0\leq s _ i\lt i\ (1\leq i\leq Q)
  • 0xiN (1iQ)0\leq x _ i\leq N\ (1\leq i\leq Q)
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN

A1A _ 1 A2A _ 2 \ldots ANA _ N

QQ

t1t _ 1 s1s _ 1 x1x _ 1

t2t _ 2 s2s _ 2 x2x _ 2

\vdots

tQt _ Q sQs _ Q xQx _ Q

Output

Print QQ lines. The ii-th line (1iQ)(1\leq i\leq Q) should contain the length of the sequence numbered ii immediately after the ii-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 A=(1,8,7,4,5,6,3,2,9,10)A=(1,8,7,4,5,6,3,2,9,10) of length 1010. He lets A=(1,8,7,4,5,6,3,2,9,10)A=(1,8,7,4,5,6,3,2,9,10) be the sequence numbered 00, and then begins the series of operations.

In the first operation, he removes elements greater than 44 from the sequence numbered 00, namely 8,7,5,6,9,108,7,5,6,9,10, and creates a new sequence numbered 11 with these elements. After this operation, the sequences numbered 00 and 11 are (1,4,3,2)(1,4,3,2) and (8,7,5,6,9,10)(8,7,5,6,9,10), respectively.

In the second operation, he removes the elements following the 22-nd element from the sequence numbered 11, namely 5,6,9,105,6,9,10, and creates a new sequence numbered 22 with these elements. After this operation, the sequences numbered 00, 11, and 22 are (1,4,3,2)(1,4,3,2), (8,7)(8,7), and (5,6,9,10)(5,6,9,10), respectively.

For the third and subsequent operations, the sequences numbered 0,1,2,,i0,1,2,\ldots,i after the ii-th operation are as follows:

  • (1,2),(8,7),(5,6,9,10),(4,3)(1,2),(8,7),(5,6,9,10),(4,3)
  • (1,2),(8,7),(5),(4,3),(6,9,10)(1,2),(8,7),(5),(4,3),(6,9,10)
  • (1),(8,7),(5),(4,3),(6,9,10),(2)(1),(8,7),(5),(4,3),(6,9,10),(2)

The length of the sequence numbered ii after the ii-th operation for i=1,2,,5i=1,2,\ldots,5 is 6,4,2,3,16,4,2,3,1. 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