CF2223E.Zhily and Permutation

NOI/NOI+/CTSC

通过率:0%

时间限制:2.50s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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{∗}} aa and bb of length nn.

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

  • i=argmax⁡k∈(l,r)aki = \operatorname*{argmax}\limits_{k \in (l, r)} a_k†^{\text{†}};
  • j=argmax⁡k∈(l,r)bkj = \operatorname*{argmax}\limits_{k \in (l, r)} b_k.

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

The sequence f(I,k)f(I, k) is defined as f(I,k)={[ ]if k=0 or l+1≥rg(I)+f(next⁡(I),k−1)otherwisef(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 mm operations:

  • 1 l r k: Output the maximum number of consecutive 11s in f((l,r),k)f((l, r), k).
  • 2 x y: Assign yy to pxp_x.

∗^{\text{∗}}A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array), and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

†^{\text{†}}argmax⁡k∈(l,r)\operatorname*{argmax}\limits_{k \in (l, r)} aka_k denotes the unique index kk (l<k<rl \lt k \lt r) such that ak=max⁡x∈(l,r)axa_k = \max\limits_{x \in (l, r)} a_x.

‡^{\text{‡}}Here, [1]m[1]^m represents a sequence of length mm consisting of all 11s.

§^{\text{§}}Here, [ ][~] represents the empty sequence, and the operator ++ between two sequences indicates their concatenation.

芝莉和吉莉喜欢在一个序列上跳跃。她们根据某种规则移动,在整个过程中,她们从当前所在位置对应的区间中汲取能量。她们利用这些能量来恢复逻辑稳定性。

给定两个长度为 nn 的排列∗^{\text{∗}} aa 和 bb。

对于任意开区间 I=(l,r)I = (l, r),其中 0≤l<r≤n+10 \le l \lt r \le n+1 且满足 l+1<rl + 1 \lt r,我们定义 next⁡(I)=(min⁡(i,j),max⁡(i,j))\operatorname{next}(I) = (\min(i, j), \max(i,j)),其中

  • i=argmax⁡k∈(l,r)aki = \operatorname*{argmax}\limits_{k \in (l, r)} a_k†^{\text{†}};
  • j=argmax⁡k∈(l,r)bkj = \operatorname*{argmax}\limits_{k \in (l, r)} b_k。

还给定一个长度为 nn 的、下标从 00 开始的非负序列 pp。序列 g(I)g(I) 定义为
g(I)={[0](pl=0)[1]pl(pl>0)g(I) = \begin{cases} [0] & (p_l = 0) \\ [1]^{p_l} & (p_l \gt 0) \end{cases}‡^{\text{‡}}。

序列 f(I,k)f(I, k) 定义为
f(I,k)={[ ]若 k=0 或 l+1≥rg(I)+f(next⁡(I),k−1)否则f(I, k) = \begin{cases} [~] & \text{若 } k=0 \text{ 或 } l+1\ge r \\ g(I) + f(\operatorname{next}(I), k-1) & \text{否则} \end{cases}§^{\text{§}}。

你需要执行 mm 次操作:

  • 1 l r k:输出 f((l,r),k)f((l, r), k) 中最长连续 11 的个数。
  • 2 x y:将 pxp_x 赋值为 yy。

∗^{\text{∗}} 长度为 nn 的排列是指由 11 到 nn 中 nn 个互不相同的整数以任意顺序组成的数组。例如,[2,3,1,5,4][2,3,1,5,4] 是一个排列,但 [1,2,2][1,2,2] 不是排列(数组中 22 出现了两次),[1,3,4][1,3,4] 也不是排列(此时 n=3n=3,但数组中出现了 44)。

†^{\text{†}} argmax⁡k∈(l,r)ak\operatorname*{argmax}\limits_{k \in (l, r)} a_k 表示唯一满足 l<k<rl \lt k \lt r 且 ak=max⁡x∈(l,r)axa_k = \max\limits_{x \in (l, r)} a_x 的下标 kk。

‡^{\text{‡}} 这里,[1]m[1]^m 表示一个长度为 mm、全部由 11 组成的序列。

§^{\text{§}} 这里,[ ][~] 表示空序列,而两个序列之间的运算符 ++ 表示它们的拼接(连接)。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains two integers nn and mm (1≤n,m≤2⋅1051 \le n, m \le 2 \cdot 10^5) — the length of the permutations and the number of operations.

The second line contains nn distinct integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤n1 \le a_i \le n) — the permutation aa.

The third line contains nn distinct integers b1,b2,…,bnb_1, b_2, \ldots, b_n (1≤bi≤n1 \le b_i \le n) — the permutation bb.

The fourth line contains nn integers p0,p1,…,pn−1p_0, p_1, \ldots, p_{n - 1} (0≤pi≤1090 \le p_i \le 10^9) — the sequence pp.

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

  • 1 l r k (0≤l<r≤n+1,1≤k≤n0\le l \lt r \le n + 1, 1\le k\le n) — Output the maximum number of consecutive 11s in f((l,r),k)f((l, r), k).
  • 2 x y (0≤x<n0 \le x \lt n, 0≤y≤1090 \le y \le 10^9) — Assign yy to pxp_x.

It is guaranteed that the sums of nn and mm over all test cases do not exceed 4⋅1054 \cdot 10^5, respectively.

每个测试包含多个测试用例。第一行包含测试用例数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n,m≤2⋅1051 \le n, m \le 2 \cdot 10^5)—— 分别表示排列的长度与操作次数。

第二行包含 nn 个互不相同的整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤n1 \le a_i \le n)—— 排列 aa。

第三行包含 nn 个互不相同的整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(1≤bi≤n1 \le b_i \le n)—— 排列 bb。

第四行包含 nn 个整数 p0,p1,…,pn−1p_0, p_1, \ldots, p_{n - 1}(0≤pi≤1090 \le p_i \le 10^9)—— 序列 pp。

接下来的 mm 行中,每行描述一个操作,格式为以下之一:

  • 1 l r k(0≤l<r≤n+10\le l \lt r \le n + 1, 1≤k≤n1\le k\le n)—— 输出 f((l,r),k)f((l, r), k) 中连续 1 的最大个数。
  • 2 x y(0≤x<n0 \le x \lt n, 0≤y≤1090 \le y \le 10^9)—— 将 pxp_x 赋值为 yy。

保证所有测试用例中 nn 的总和与 mm 的总和分别不超过 4⋅1054 \cdot 10^5。

输出格式

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

对于每个类型为 11 的操作,在一行中输出答案。

输入输出样例

  • 输入#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

    输出#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

说明/提示

In the first test case:

  • f((0,4),1)=g(0,4)+f((2,3),0)=[1,1]+[ ]→2f((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]+[ ]→3f((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]+[ ]→5f((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]+[ ]→2f((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]+[ ]→0f((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]+[ ]→0f((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]+[ ]→0f((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]+[ ]→3f((3,5),2) = g(3,5) + f((4,4),1) = [1,1,1] + [~] \to \mathbf{3}

在第一个测试用例中:

  • f((0,4),1)=g(0,4)+f((2,3),0)=[1,1]+[ ]→2f((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]+[ ]→3f((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]+[ ]→5f((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]+[ ]→2f((0,6),2) = g(0,6) + f((3,4),1) = [1,1] + [~] \to \mathbf{2}

在第二个测试用例中:

  • f((2,5),1)=g(2,5)+f((3,4),0)=[0]+[ ]→0f((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]+[ ]→0f((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]+[ ]→0f((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]+[ ]→3f((3,5),2) = g(3,5) + f((4,4),1) = [1,1,1] + [~] \to \mathbf{3}

输入解题思路,AI测评打分。不知道怎么写?

首页