#abc342g. G - Retroactive Range Chmax

G - Retroactive Range Chmax

Score: 625625 points

问题描述

你将得到一个整数序列 A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N),其长度为 NN

按照顺序处理 QQ 个操作。操作有三种类型:

  • 类型-1操作由三个整数组成的三元组 (l,r,x)(l,r,x) 表示,对应于将每个 AiA_i(对于 i=l,l+1,,ri=l,l+1,\ldots,r)替换为 max{Ai,x}\max\lbrace A_i,x\rbrace
  • 类型-2操作由一个整数 ii 表示,对应于取消第 ii 次操作(保证第 ii 次操作是未被取消的类型1操作)。新的序列 AA 可以通过执行所有未被取消的类型-1操作从初始状态获得。
  • 类型-3操作由一个整数 ii 表示,对应于输出当前的 AiA_i 值。

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

Problem Statement

You are given an integer sequence A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N) of length NN.

Process QQ operations in order. There are three types of operations:

  • A type-1 operation is represented by a triple of integers (l,r,x)(l,r,x), which corresponds to replacing AiA_i with max{Ai,x}\max\lbrace A_i,x\rbrace for each i=l,l+1,,ri=l,l+1,\ldots,r.
  • A type-2 operation is represented by an integer ii, which corresponds to canceling the ii-th operation (it is guaranteed that the ii-th operation is of type 1 and has not already been canceled). The new sequence AA can be obtained by performing all type-1 operations that have not been canceled, starting from the initial state.
  • A type-3 operation is represented by an integer ii, which corresponds to printing the current value of AiA_i.

Constraints

  • 1N2×1051\leq N\leq2\times10^5
  • 1Ai109 (1iN)1\leq A_i\leq10^9\ (1\leq i\leq N)
  • 1Q2×1051\leq Q\leq2\times10^5
  • In a type-1 operation, 1lrN1\leq l\leq r\leq N and 1x1091\leq x\leq10^9.
  • In a type-2 operation, ii is not greater than the number of operations given before, and 1i1\leq i.
  • In a type-2 operation, the ii-th operation is of type 1.
  • In type-2 operations, the same ii does not appear multiple times.
  • In a type-3 operation, 1iN1\leq i\leq N.
  • 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

query1\operatorname{query}_1

query2\operatorname{query}_2

\vdots

queryQ\operatorname{query}_Q

Here, queryk (1kQ)\operatorname{query}_k\ (1\leq k\leq Q) represents the kk-th operation, and depending on the type of the kk-th operation, one of the following is given.

For a type-1 operation, the following is given, meaning that the kk-th operation is a type-1 operation represented by (l,r,x)(l,r,x):

11 ll rr xx

For a type-2 operation, the following is given, meaning that the kk-th operation is a type-2 operation represented by ii:

22 ii

For a type-3 operation, the following is given, meaning that the kk-th operation is a type-3 operation represented by ii:

33 ii

Output

Let qq be the number of type-3 operations. Print qq lines. The ii-th line (1iq)(1\leq i\leq q) should contain the value that should be printed for the ii-th given type-3 operation.

Sample Input 1

6
2 7 1 8 2 8
15
3 1
3 3
3 4
1 1 5 4
3 1
3 3
3 4
1 3 6 9
3 1
3 3
3 4
2 4
3 1
3 3
3 4

Sample Output 1

2
1
8
4
4
8
4
9
9
2
9
9

Initially, the sequence AA is (2,7,1,8,2,8)(2,7,1,8,2,8).

For the 11-st, 22-nd, 33-rd operations, print the values of A1,A3,A4A_1, A_3, A_4, which are 2,1,82,1,8, respectively.

The 44-th operation replaces the values of A1,A2,A3,A4,A5A_1, A_2, A_3, A_4, A_5 with max{Ai,4}\max\lbrace A_i,4\rbrace. Just after this operation, AA is (4,7,4,8,4,8)(4,7,4,8,4,8).

For the 55-th, 66-th, 77-th operations, print the values of A1,A3,A4A_1, A_3, A_4 at this point, which are 4,4,84,4,8, respectively.

The 88-th operation replaces the values of A3,A4,A5,A6A_3, A_4, A_5, A_6 with max{Ai,9}\max\lbrace A_i,9\rbrace. Just after this operation, AA is (4,7,9,9,9,9)(4,7,9,9,9,9).

For the 99-th, 1010-th, 1111-th operations, print the values of A1,A3,A4A_1, A_3, A_4 at this point, which are 4,9,94,9,9, respectively.

The 1212-th operation cancels the 44-th operation. Just after this operation, AA is (2,7,9,9,9,9)(2,7,9,9,9,9).

For the 1313-th, 1414-th, 1515-th operations, print the values of A1,A3,A4A_1, A_3, A_4 at this point, which are 2,9,92,9,9, respectively.

Sample Input 2

24
721 78 541 256 970 478 370 467 344 542 43 166 619 17 592 222 983 729 338 747 62 452 815 838
35
3 10
3 8
3 8
3 13
3 9
1 1 17 251
3 3
3 19
3 13
3 22
3 1
3 15
3 18
3 10
3 15
1 16 19 883
1 8 23 212
3 5
3 13
2 6
3 15
1 5 18 914
2 17
3 20
1 23 23 56
3 13
2 25
3 13
3 13
3 10
2 16
1 17 22 308
3 19
3 17
3 7

Sample Output 2

542
467
467
619
344
541
338
619
452
721
592
729
542
592
970
619
592
747
914
914
914
914
338
983
914

update @ 2024/3/10 01:37:24