#P16446. [XJTUPC 2026] 修罗指数

    ID: 18477 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>线段树2026高校校赛

[XJTUPC 2026] 修罗指数

Problem Description

You are playing a “multi-character romance simulation game” and are trying to romance NN characters at the same time. For the ii-th character, there are two key values:

  • aia_i: her tolerance toward you;
  • bib_i: her expectation of you.

Initially, the status of all characters is given and identical: ai=A,bi=Ba_i = A, b_i = B (1≤i≤N1\le i \le N).

Next, you will perform QQ actions. Each action is one of the following three types:

  • 1 r x1\ r\ x: you “mess up collectively” with the first rr characters, causing their tolerance to decrease.

    That is, for all ii (1≤i≤r1\leq i\leq r), ai←min⁡{ai,x}a_{i} \gets \min \{ a_{i}, x \}.

  • 2 l x2\ l\ x: you give gifts to the ll-th through the NN-th characters, causing their expectations to increase.

    That is, for all ii (l≤i≤Nl\leq i \leq N), bi←max⁡{bi,x}b_{i} \gets \max \{ b_{i}, x \}.

  • 3 l r3\ l\ r: query the “Shura Index” of the ll-th through the rr-th characters.

    The “Shura Index” is defined as ∑i=lr∣ai−bi∣\sum_{i=l}^r |a_{i}-b_{i}|.

Input Format

The first line contains three integers N,AN, A and BB (1≤N≤5×105,−109≤A,B≤1091\le N\le 5 \times 10^5, -10^9\le A,B\le 10^9), separated by a single space, representing the number of characters, the initial tolerance value, and the initial expectation value.

The second line contains an integer QQ (1≤Q≤5×1051\le Q\le 5 \times 10^5), indicating the number of actions.

The next QQ lines each contain three integers separated by a single space. These three integers correspond to one of the following cases, representing one action:

  • 1 r x1\ r\ x (1≤r≤N,−109≤x≤1091\le r\le N, -10^9 \le x \le 10^9), meaning that for all ii (1≤i≤r1\leq i\leq r), ai←min⁡{ai,x}a_{i} \gets \min \{ a_{i}, x \}.
  • 2 l x2\ l\ x (1≤l≤N,−109≤x≤1091\le l\le N, -10^9 \le x \le 10^9), meaning that for all ii (l≤i≤Nl\leq i \leq N), bi←max⁡{bi,x}b_{i} \gets \max \{ b_{i}, x \}.
  • 3 l r3\ l\ r (1≤l≤r≤N1\le l\le r\le N), meaning to query the “Shura Index” ∑i=lr∣ai−bi∣\sum_{i=l}^r |a_{i}-b_{i}| for the ll-th through the rr-th characters.

Output Format

For each action that queries the “Shura Index”, output one line containing one integer, representing the value of the “Shura Index”.

11 38 11
21
3 4 7
2 3 23
3 2 6
2 9 29
3 3 4
1 11 13
3 2 7
1 1 38
3 1 8
1 9 11
3 2 8
1 11 33
3 1 10
2 9 25
3 2 10
1 10 31
3 1 3
1 3 39
3 3 8
2 7 21
3 5 9
108
87
30
52
64
72
106
106
12
72
66

Hint

Translated by ChatGPT 5