终局将剩下什么?(简单版)AI (CI翻译)
This is the easy version of the problem. The only difference between the two versions is the set of allowed values for the initial array and for $x$ in operations of type $1$. In this version, all these values belong to $\{-1,0,1\}$. You can make hacks only if both versions of the problem are solved.
这是本题的简单版本。两个版本之间唯一的区别是初始数组以及类型 $1$ 操作中的 $x$ 所允许的取值集合。在本版本中,所有这些值都属于 $\{-1,0,1\}$。只有在两个版本的问题都解决后,才能进行 hack。AI (CI翻译)
Before her final sortie, Chtholly asks Willem three questions.
在最后一次出击前,Chtholly 向 Willem 提出了三个问题。AI (CI翻译)
The second is this: what will remain if the sky truly reaches its end?
第二个问题是:如果天空真的走到了尽头,最终会剩下什么?AI (CI翻译)
Willem cannot answer her directly. Instead, he opens a chronicle containing $n$ records, numbered from $1$ to $n$. Each record holds an integer: a positive value represents hope, while a negative value represents despair.
Willem 无法直接回答她。于是,他打开了一本包含 $n$ 条记录的编年史,这些记录编号为 $1$ 至 $n$。每条记录都存储着一个整数:正数代表希望,负数代表绝望。AI (CI翻译)
The initial contents of the chronicle form an array $a_1,a_2,\ldots,a_n$, called version $0$. Chtholly then performs $q$ operations. For each $1\le i\le q$, the $i$-th operation creates a new version $i$ from version $i-1$.
编年史的初始内容构成数组 $a_1,a_2,\ldots,a_n$,称为 版本 $0$。随后,Chtholly 执行 $q$ 次操作。对于每个 $1\le i\le q$,第 $i$ 次操作根据版本 $i-1$ 创建一个新的 版本 $i$。AI (CI翻译)
Each operation has one of the following four types:
每次操作属于以下四种类型之一:AI (CI翻译)
$\texttt{1 l r x}$: set$a_k\gets x$for every$l\le k\le r$.$\texttt{2 l r}$: set$a_k\gets -a_k$for every$l\le k\le r$.$\texttt{3 l r}$: set$a_k\gets\max(a_k,0)$for every$l\le k\le r$.$\texttt{4 p}$: consider the value at position$p$in every previous version$0,1,\ldots, i-1$. Let these values be$b_0,b_1,\ldots,b_{i-1}$. Find the maximum sum over all non-empty subarrays$^{\text{∗}}$of this sequence.
$\texttt{1 l r x}$:对于每个$l\le k\le r$,令$a_k\gets x$。$\texttt{2 l r}$:对于每个$l\le k\le r$,令$a_k\gets -a_k$。$\texttt{3 l r}$:对于每个$l\le k\le r$,令$a_k\gets\max(a_k,0)$。$\texttt{4 p}$:考虑每个此前版本$0,1,\ldots,i-1$中位置$p$的值。设这些值为$b_0,b_1,\ldots,b_{i-1}$。求该序列所有非空子数组$^{\text{∗}}$中的最大元素和。
If the operation is of type $1$, $2$, or $3$, the specified modification is applied to version $i-1$ to obtain version $i$. An operation of type $4$ does not modify the array, so version $i$ is identical to version $i-1$.
如果操作类型为 $1$、$2$ 或 $3$,则将指定修改应用于版本 $i-1$,得到版本 $i$。类型 $4$ 的操作不会修改数组,因此版本 $i$ 与版本 $i-1$ 相同。AI (CI翻译)
The operations are encoded and must be processed in order. Their decoding depends on $\mathrm{lastans}$, which is updated after every operation of type $4$.
**操作经过编码,必须按照顺序处理。**它们的解码依赖于 $\mathrm{lastans}$,而 $\mathrm{lastans}$ 会在每次类型 $4$ 操作后更新。AI (CI翻译)
Help Willem answer every operation of type $4$.
请帮助 Willem 回答每个类型 $4$ 的操作。AI (CI翻译)
$^{\text{∗}}$An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.
$^{\text{∗}}$如果数组 $c$ 可以通过从数组 $b$ 的开头删除若干个(可以为零个或全部)元素,并从末尾删除若干个(可以为零个或全部)元素得到,则称数组 $c$ 是数组 $b$ 的子数组。AI (CI翻译)
Input
输入格式
AI (CI翻译)Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
每个测试包含多个测试用例。第一行包含测试用例数量 $t$($1 \le t \le 10^4$)。接下来给出各测试用例的描述。AI (CI翻译)
The first line of each test case contains two integers $n$ and $q$ ($1\le n,q\le5\cdot10^5$) — the length of the array and the number of operations.
每个测试用例的第一行包含两个整数 $n$ 和 $q$($1\le n,q\le5\cdot10^5$)——数组长度以及操作数量。AI (CI翻译)
The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($a_i\in\{-1,0,1\}$) — the array in version $0$.
每个测试用例的第二行包含 $n$ 个整数 $a_1,a_2,\ldots,a_n$($a_i\in\{-1,0,1\}$)——版本 $0$ 中的数组。AI (CI翻译)
Each of the next $q$ lines describes one operation in one of the following encoded formats: The first integer on the line is the operation type.
接下来的 $q$ 行中,每行描述一个经过编码的操作,格式如下。每行的第一个整数表示操作类型。AI (CI翻译)
$\texttt{1 u v x}$($0\le u,v \lt 2^{64}$,$x\in\{-1,0,1\}$);$\texttt{2 u v}$($0\le u,v \lt 2^{64}$);$\texttt{3 u v}$($0\le u,v \lt 2^{64}$);$\texttt{4 u}$($0\le u \lt 2^{64}$).
$\texttt{1 u v x}$($0\le u,v \lt 2^{64}$,$x\in\{-1,0,1\}$);$\texttt{2 u v}$($0\le u,v \lt 2^{64}$);$\texttt{3 u v}$($0\le u,v \lt 2^{64}$);$\texttt{4 u}$($0\le u \lt 2^{64}$)。
The operations are encoded and must be processed in order. Their decoding depends on a value $\mathrm{lastans}$.
操作经过编码,必须按照顺序处理。它们的解码依赖于 $\mathrm{lastans}$。AI (CI翻译)
Initially, $\mathrm{lastans}=0$. After answering an operation of type $4$, set $\mathrm{lastans}$ to the least non-negative residue of its answer modulo $2^{64}$. Operations of all other types leave $\mathrm{lastans}$ unchanged.
初始时,$\mathrm{lastans}=0$。回答一个类型 $4$ 的操作后,将 $\mathrm{lastans}$ 设为其答案对 $2^{64}$ 取模后的最小非负剩余。其他类型的操作不会改变 $\mathrm{lastans}$。AI (CI翻译)
For every encoded coordinate $y$, define $d(y)=\left(\left(y\oplus\mathrm{lastans}\right)\bmod n\right)+1$. Here, $\oplus$ denotes the bitwise XOR operation.
对于每个经过编码的坐标 $y$,定义
$$d(y)=\left(\left(y\oplus\mathrm{lastans}\right)\bmod n\right)+1$$
其中,$\oplus$ 表示按位异或运算。AI (CI翻译)
- For an operation
$\texttt{1 u v x}$, let$l=\min(d(u),d(v))$and$r=\max(d(u),d(v))$. The value$x$is not encoded. - For an operation
$\texttt{2 u v}$or$\texttt{3 u v}$, let$l=\min(d(u),d(v))$and$r=\max(d(u),d(v))$. - For an operation
$\texttt{4 u}$, let$p=d(u)$.
- 对于操作
$\texttt{1 u v x}$,令$l=\min(d(u),d(v))$,$r=\max(d(u),d(v))$。值$x$未经过编码。 - 对于操作
$\texttt{2 u v}$或$\texttt{3 u v}$,令$l=\min(d(u),d(v))$,$r=\max(d(u),d(v))$。 - 对于操作
$\texttt{4 u}$,令$p=d(u)$。
The operation type is not encoded. Do not forget to update $\mathrm{lastans}$ after answering each operation of type $4$.
操作类型未经过编码。回答每个类型 $4$ 的操作后,不要忘记更新 $\mathrm{lastans}$。AI (CI翻译)
It is guaranteed that the sum of $n$ over all test cases does not exceed $5\cdot10^5$.
保证所有测试用例的 $n$ 之和不超过 $5\cdot10^5$。AI (CI翻译)
It is guaranteed that the sum of $q$ over all test cases does not exceed $5\cdot10^5$.
保证所有测试用例的 $q$ 之和不超过 $5\cdot10^5$。AI (CI翻译)
Output
输出格式
AI (CI翻译)For every operation of type $4$, output a single integer — the maximum sum of a non-empty subarray of the sequence of the values at position $p$ over all versions preceding this operation.
对于每个类型 $4$ 的操作,输出一个整数——在该操作之前的所有版本中,位置 $p$ 的值所组成序列的非空子数组的最大元素和。AI (CI翻译)
Note
说明
AI (CI翻译)In the first test case, for the first operation, $\mathrm{lastans}=0$, so the encoded coordinate $1$ is decoded into position $2$. Only version $0$ is considered. The value at position $2$ is $-1$, hence the answer is $-1$.
在第一个测试用例中,对于第一次操作,$\mathrm{lastans}=0$,因此编码坐标 $1$ 被解码为位置 $2$。此时只考虑版本 $0$。位置 $2$ 的值为 $-1$,所以答案为 $-1$。AI (CI翻译)
Now $\mathrm{lastans}=2^{64}-1=18\,446\,744\,073\,709\,551\,615$. Therefore the encoded interval $[18\,446\,744\,073\,709\,551\,615,18\,446\,744\,073\,709\,551\,613]$ is decoded into $[1,3]$, and the encoded coordinate $18\,446\,744\,073\,709\,551\,614$ is decoded into position $2$.
此时 $\mathrm{lastans}=2^{64}-1=18\,446\,744\,073\,709\,551\,615$。因此,编码区间 $[18\,446\,744\,073\,709\,551\,615,18\,446\,744\,073\,709\,551\,613]$ 被解码为 $[1,3]$,编码坐标 $18\,446\,744\,073\,709\,551\,614$ 被解码为位置 $2$。AI (CI翻译)
Before the second query, the values at position $2$ in versions $0$, $1$, and $2$ are $-1$, $-1$, and $1$, respectively. Their maximum non-empty subarray sum is $1$.
在第二次询问之前,版本 $0$、$1$ 和 $2$ 中位置 $2$ 的值分别为 $-1$、$-1$ 和 $1$。它们的最大非空子数组和为 $1$。AI (CI翻译)
Before the third query, the values at position $2$ in versions $0,1,\ldots,5$ form sequence $[-1,-1,1,1,1,-1]$. The three consecutive values equal to $1$ form a subarray with sum $3$.
在第三次询问之前,版本 $0,1,\ldots,5$ 中位置 $2$ 的值组成序列 $[-1,-1,1,1,1,-1]$。其中连续的三个值 $1$ 构成一个和为 $3$ 的子数组。AI (CI翻译)
Notice that the first, second, and third queries create versions $1$, $3$, and $6$, respectively, even though they do not change the array.
注意,第一次、第二次和第三次询问分别创建了版本 $1$、$3$ 和 $6$,尽管它们并未改变数组。AI (CI翻译)
In the second test case, the first query asks about position $1$, so its answer is $1$. Then $\mathrm{lastans}=1$, and the encoded operation $\texttt{1 0 3 -1}$ is decoded into $\texttt{1 2 3 -1}$.
在第二个测试用例中,第一次询问询问的是位置 $1$,因此答案为 $1$。此时 $\mathrm{lastans}=1$,编码操作 $\texttt{1 0 3 -1}$ 被解码为 $\texttt{1 2 3 -1}$。AI (CI翻译)
Before the second query, the values at position $3$ in versions $0$, $1$, and $2$ are $1$, $1$, and $-1$, respectively, so the answer is $2$.
在第二次询问之前,版本 $0$、$1$ 和 $2$ 中位置 $3$ 的值分别为 $1$、$1$ 和 $-1$,因此答案为 $2$。AI (CI翻译)
Afterwards, $\mathrm{lastans}=2$. The encoded operations $\texttt{2 2 3}$ and $\texttt{3 3 0}$ are decoded into $\texttt{2 1 2}$ and $\texttt{3 2 3}$, respectively. Before the last query, the values at position $2$ in versions $0,1,\ldots,5$ form sequence $[-1,-1,-1,-1,1,1]$, whose maximum non-empty subarray sum is $2$.
之后,$\mathrm{lastans}=2$。编码操作 $\texttt{2 2 3}$ 和 $\texttt{3 3 0}$ 分别被解码为 $\texttt{2 1 2}$ 和 $\texttt{3 2 3}$。在最后一次询问之前,版本 $0,1,\ldots,5$ 中位置 $2$ 的值组成序列 $[-1,-1,-1,-1,1,1]$,其最大非空子数组和为 $2$。AI (CI翻译)
样例
2
4 8
1 -1 1 -1
4 1
2 18446744073709551615 18446744073709551613
4 18446744073709551614
3 0 3
1 0 2 -1
4 0
2 2 0
4 0
3 6
1 -1 1
4 0
1 0 3 -1
4 3
2 2 3
3 3 0
4 3
-1
1
3
1
1
2
2
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。