#P16524. 余生的第一天

余生的第一天

Background

Pressing the shutter again and again without thinking.
Is it to capture the happiness at that moment?
Or to capture who I was at that moment?

Problem Description

There is a sequence ss with nn elements.

There are qq operations. Each operation is one of the following two types:

  1. Query. Given ll, rr, and VV, compute:
$$\max^r_{i=l-1} \left (\sum^i_{\substack{k=l \\ |s_k| \le V}}s_k + \sum^r_{\substack{k=i+1 \\ |s_k| > V}}s_k \right)$$
  1. Point update. Given ww and kk, set sws_w to kk.

Input Format

This problem is forced online. For ll, rr, or ww in each operation, let the answer to the previous query be lastlast. Initially, last=0last=0.

Then decrypt as follows:

  • l←(l⊗∣last∣)mod  n+1l \gets (l \otimes |last|) \mod n +1
  • r←(r⊗∣last∣)mod  n+1r \gets (r \otimes |last|) \mod n +1
  • w←(w⊗∣last∣)mod  n+1w \gets (w \otimes |last|) \mod n +1

Here, ⊗\otimes is the bitwise XOR operation. If l>rl>r, please swap ll and rr.

The first line contains two integers nn and qq.

The second line contains nn integers representing sis_i.

The next qq lines each contain either 1 l r V or 2 w k, representing an operation.

Output Format

For each query, output one integer per line as the answer.

5 5
-2 1 3 -4 8
1 1 5 3
2 1 7
2 3 -6
1 2 4 5
1 1 5 2
0
11
12

Hint

Constraints

Let GG be the maximum value among all ∣si∣,∣V∣,∣k∣\lvert s_i \rvert,\lvert V \rvert,\lvert k \rvert within a test point.

For 100%100\% of the data, it is guaranteed that: 1≤n≤5×1041 \le n \le 5 \times 10^4, 1≤l,r≤n1 \le l,r \le n, 1≤w≤n1 \le w \le n, $\lvert s_i \rvert,\lvert V \rvert,\lvert k \rvert \le 10^8$, and V≥0V \ge 0.

Subtask Score n≤n \le q≤q \le G≤G \le Special Property
11 55 55 1010 None
22 200200 < 10310^3 ^
33 1010 10310^3 10510^5
44 1515 5×1035 \times 10^3 ^
55 5×1045 \times 10^4 10810^8 A
66 1010 ^ B
77 4040 None

Special Property A: There are no update operations.

Special Property B: si≥0s_i \ge 0.

Translated by ChatGPT 5