Codeforces Round 994 (Div. 2)
F
MEX OR Mania
Codeforces
2700
原题
← E→
翻译中…

An integer sequence $b_1, b_2, \ldots, b_n$ is good if $\operatorname{mex}(b_1, b_2, \ldots, b_n) - (b_1 | b_2 | \ldots | b_n) = 1$. Here, $\operatorname{mex(c)}$ denotes the MEX$^{\text{∗}}$ of the collection $c$, and $|$ is the bitwise OR operator.

翻译中…

Shohag has an integer sequence $a_1, a_2, \ldots, a_n$. He will perform the following $q$ updates on $a$:

翻译中…
  • $i$ $x$ — increase $a_i$ by $x$.
翻译中…

After each update, help him find the length of the longest good subarray$^{\text{†}}$ of $a$.

翻译中…

$^{\text{∗}}$The minimum excluded (MEX) of a collection of integers $c_1, c_2, \ldots, c_k$ is defined as the smallest non-negative integer $y$ which does not occur in the collection $c$. $^{\text{†}}$An array $d$ is a subarray of an array $f$ if $d$ can be obtained from $f$ by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

翻译中…

Input

翻译中…

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.

翻译中…

The first line of each test case contains two space-separated integers $n$ and $q$ ($1 \le n, q \le 10^5$).

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le n$).

翻译中…

The next $q$ lines of each test case are of the following form:

翻译中…
  • $i$ $x$ ($1 \le i, x \le n$) — it means you should increase $a_i$ by $x$.
翻译中…

It is guaranteed that the sum of $n$ over all test cases doesn't exceed $10^5$ and the sum of $q$ doesn't exceed $10^5$.

翻译中…

Output

翻译中…

For each test case, output $q$ lines — on the $i$-th line output the length of the longest good subarray of $a$ after the $i$-th update.

翻译中…

Note

翻译中…

In the first test case, after the first update, the array becomes $[0, 0, 1, 0, 1, 1]$, and here the whole array is good because $\operatorname{mex}([0, 0, 1, 0, 1, 1]) - (0 | 0 | 1 | 0 | 1 | 1) = 2 - 1 = 1$.

翻译中…

After the second update, the array becomes $[0, 0, 3, 0, 1, 1]$, and here the subarray $[0, 1, 1]$ has the maximum length among all the good subarrays.

翻译中…

Finally, after the third update, the array becomes $[0, 0, 3, 0, 1, 4]$, and here the subarrays $[0, 0]$ and $[0, 1]$ both have the maximum length among all the good subarrays.

翻译中…

样例

Input #1
2
6 3
0 0 1 0 1 0
6 1
3 2
6 3
3 1
1 3 1
1 1
Output #1
6
3
2
0
InputCopy OutputCopy
题目信息
题号
2049F
时间限制
4 s
内存限制
1024 MB
标签
位运算
暴力
数据结构
并查集
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。