Codeforces Round 1097 (Div. 1, Based on Zhili Cup 2026)
E
Zhily and Permutation
Codeforces
3500
原题
← DF →
翻译中…

Zhily and Jily enjoy jumping around on a sequence. They move according to some rule, and throughout the process, they draw energy from the interval corresponding to their current positions. They use this energy to restore logical stability.

翻译中…

You are given two permutations$^{\text{∗}}$ $a$ and $b$ of length $n$.

翻译中…

For any open interval $I = (l, r)$ where $0 \le l \lt r \le n+1$ and $l + 1 \lt r$ holds, we define $\operatorname{next}(I) = (\min(i, j), \max(i,j))$, where

翻译中…
  • $i = \operatorname*{argmax}\limits_{k \in (l, r)} a_k$$^{\text{†}}$;
  • $j = \operatorname*{argmax}\limits_{k \in (l, r)} b_k$.
翻译中…

You are also given a $0$-indexed non-negative sequence $p$ of length $n$. The sequence $g(I)$ is defined as $g(I) = \begin{cases} [0] & (p_l = 0) \\ [1]^{p_l} & (p_l \gt 0) \end{cases}$$^{\text{‡}}$.

翻译中…

The sequence $f(I, k)$ is defined as $f(I, k) = \begin{cases} [~] & \text{if } k=0 \text{ or } l+1\ge r \\ g(I) + f(\operatorname{next}(I), k-1) & \text{otherwise} \end{cases}$$^{\text{§}}$.

翻译中…

You need to perform $m$ operations:

翻译中…
  • 1 l r k: Output the maximum number of consecutive $1$s in $f((l, r), k)$.
  • 2 x y: Assign $y$ to $p_x$.
翻译中…

$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array). $^{\text{†}}$$\operatorname*{argmax}\limits_{k \in (l, r)}$ $a_k$ denotes the unique index $k$ ($l \lt k \lt r$) such that $a_k = \max\limits_{x \in (l, r)} a_x$.$^{\text{‡}}$Here, $[1]^m$ represents a sequence of length $m$ consisting of all $1$s.$^{\text{§}}$Here, $[~]$ represents the empty sequence, and the operator $+$ between two sequences indicates their concatenation.

翻译中…

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 integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) — the length of the permutations and the number of operations.

翻译中…

The second line contains $n$ distinct integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) — the permutation $a$.

翻译中…

The third line contains $n$ distinct integers $b_1, b_2, \ldots, b_n$ ($1 \le b_i \le n$) — the permutation $b$.

翻译中…

The fourth line contains $n$ integers $p_0, p_1, \ldots, p_{n - 1}$ ($0 \le p_i \le 10^9$) — the sequence $p$.

翻译中…

Each of the next $m$ lines contains an operation in one of the following formats:

翻译中…
  • 1 l r k ($0\le l \lt r \le n + 1, 1\le k\le n$) — Output the maximum number of consecutive $1$s in $f((l, r), k)$.
  • 2 x y ($0 \le x \lt n$, $0 \le y \le 10^9$) — Assign $y$ to $p_x$.
翻译中…

It is guaranteed that the sums of $n$ and $m$ over all test cases do not exceed $4 \cdot 10^5$, respectively.

翻译中…

Output

翻译中…

For each operation of type $1$, output the answer in one line.

翻译中…

Note

翻译中…

In the first test case:

翻译中…
  • $f((0,4),1) = g(0,4) + f((2,3),0) = [1,1] + [~] \to \mathbf{2}$
  • $f((1,4),2) = g(1,4) + f((2,3),1) = [1,1,1] + [~] \to \mathbf{3}$
  • $f((3,6),1) = g(3,6) + f((4,5),0) = [1,1,1,1,1] + [~] \to \mathbf{5}$
  • $f((0,6),2) = g(0,6) + f((3,4),1) = [1,1] + [~] \to \mathbf{2}$
翻译中…

In the second test case:

翻译中…
  • $f((2,5),1) = g(2,5) + f((3,4),0) = [0] + [~] \to \mathbf{0}$
  • $f((4,6),2) = g(4,6) + f((5,5),1) = [0] + [~] \to \mathbf{0}$
  • $f((0,5),1) = g(0,5) + f((2,2),0) = [0] + [~] \to \mathbf{0}$
  • $f((3,5),2) = g(3,5) + f((4,4),1) = [1,1,1] + [~] \to \mathbf{3}$
翻译中…

样例

Input #1
3
5 4
3 4 1 5 2
2 3 5 1 4
2 3 2 5 3
1 0 4 1
1 1 4 2
1 3 6 1
1 0 6 2
5 4
3 5 1 2 4
1 4 3 2 5
0 2 0 3 0
1 2 5 1
1 4 6 2
1 0 5 1
1 3 5 2
10 30
10 1 7 3 2 8 4 9 6 5
1 7 3 2 8 9 5 4 10 6
4 0 6 3 0 2 1 5 2 4
1 10 11 10
1 10 11 3
1 4 11 10
1 10 11 9
1 1 4 10
2 4 5
1 0 7 4
1 9 10 4
2 6 3
1 5 7 6
1 6 7 9
1 2 7 4
1 4 7 2
1 1 2 1
1 5 7 8
2 0 3
1 2 7 5
1 7 10 6
1 6 8 7
1 3 4 3
1 8 9 9
2 4 5
1 1 4 4
1 0 9 4
2 1 2
1 6 11 10
1 5 9 10
1 2 4 7
1 1 11 1
1 2 11 3
Output #1
2
3
5
2
0
0
0
3
0
0
0
0
0
4
0
2
0
6
5
0
2
6
5
3
0
0
0
3
3
5
6
2
6
InputCopy OutputCopy
题目信息
题号
2223E
时间限制
2.5 s
内存限制
1024 MB
标签
数据结构
分治
树

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