#P8987. [北大集训 2021] 简单数据结构

[北大集训 2021] 简单数据结构

Background

CTT2021 D2T1

Problem Description

Xiao D is a master of data structures. He especially likes studying data structures with simple forms. Today he came up with the following problem.

You have a sequence aa of length nn. You need to perform qq modifications or queries:

  1. Given vv, change every aia_i to min(ai,v)\min(a_i, v).
  2. Change every aia_i to ai+ia_i + i.
  3. Given l,rl, r, query i=lrai\sum_{i=l}^r a_i.

As a top-level data structure master, Xiao D solved this problem easily. Now he wants to test you, who are about to take part in IOI2022. He believes you can also solve it easily.

Input Format

The first line contains two positive integers n,qn, q, representing the length of the sequence and the number of modifications/queries.

The next line contains nn integers aia_i, representing the initial sequence aa.

The next qq lines each start with a positive integer opiop_i, indicating the type of the ii-th modification/query.

  • If opi=1op_i = 1, it is followed by an integer viv_i, meaning perform modification 1 once.
  • If opi=2op_i = 2, it means perform modification 2 once.
  • If opi=3op_i = 3, it is followed by two positive integers li,ril_i, r_i, meaning perform query 3 once.

Output Format

Output several lines, each containing one integer as an answer.

15 15
6 14 14 6 3 6 4 13 10 3 12 5 11 9 6
1 9
1 2
2
2
2
1 11
3 4 6
2
1 6
2
1 9
1 11
1 11
3 4 4
3 2 13
33
9
107

Hint

Subtask ID Subtask Score n,qn, q Special Property
11 1010 50005000
22 2020 200000200000 A
33 1515 opi2op_i\neq 2
44 5555

Constraints: 1n,q2×1051 \leq n, q \leq 2 \times 10^5, 0ai,vi10120 \leq a_i, v_i \leq 10^{12}.

Property A: ai,via_i, v_i are generated uniformly at random in [0,1012][0, 10^{12}], opiop_i is generated uniformly at random in [1,3][1, 3], and [li,ri][l_i, r_i] is generated uniformly at random among all valid intervals.

Translated by ChatGPT 5