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∗ a and b of length n.
For any open interval I=(l,r) where 0≤l<r≤n+1 and l+1<r holds, we define next(I)=(min(i,j),max(i,j)), where
- i=k∈(l,r)argmaxak†;
- j=k∈(l,r)argmaxbk.
You are also given a 0-indexed non-negative sequence p of length n. The sequence g(I) is defined as g(I)={[0][1]pl(pl=0)(pl>0)‡.
The sequence f(I,k) is defined as f(I,k)={[ ]g(I)+f(next(I),k−1)if k=0 or l+1≥rotherwise§.
You need to perform m operations:
- 1 l r k: Output the maximum number of consecutive 1s in f((l,r),k).
- 2 x y: Assign y to px.
∗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).
†k∈(l,r)argmax ak denotes the unique index k (l<k<r) such that ak=x∈(l,r)maxax.
‡Here, [1]m represents a sequence of length m consisting of all 1s.
§Here, [ ] represents the empty sequence, and the operator + between two sequences indicates their concatenation.
芝莉和吉莉喜欢在一个序列上跳跃。她们根据某种规则移动,在整个过程中,她们从当前所在位置对应的区间中汲取能量。她们利用这些能量来恢复逻辑稳定性。
给定两个长度为 n 的排列∗ a 和 b。
对于任意开区间 I=(l,r),其中 0≤l<r≤n+1 且满足 l+1<r,我们定义 next(I)=(min(i,j),max(i,j)),其中
- i=k∈(l,r)argmaxak†;
- j=k∈(l,r)argmaxbk。
还给定一个长度为 n 的、下标从 0 开始的非负序列 p。序列 g(I) 定义为
g(I)={[0][1]pl(pl=0)(pl>0)‡。
序列 f(I,k) 定义为
f(I,k)={[ ]g(I)+f(next(I),k−1)若 k=0 或 l+1≥r否则§。
你需要执行 m 次操作:
1 l r k:输出 f((l,r),k) 中最长连续 1 的个数。2 x y:将 px 赋值为 y。
∗ 长度为 n 的排列是指由 1 到 n 中 n 个互不相同的整数以任意顺序组成的数组。例如,[2,3,1,5,4] 是一个排列,但 [1,2,2] 不是排列(数组中 2 出现了两次),[1,3,4] 也不是排列(此时 n=3,但数组中出现了 4)。
† k∈(l,r)argmaxak 表示唯一满足 l<k<r 且 ak=x∈(l,r)maxax 的下标 k。
‡ 这里,[1]m 表示一个长度为 m、全部由 1 组成的序列。
§ 这里,[ ] 表示空序列,而两个序列之间的运算符 + 表示它们的拼接(连接)。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains two integers n and m (1≤n,m≤2⋅105) — the length of the permutations and the number of operations.
The second line contains n distinct integers a1,a2,…,an (1≤ai≤n) — the permutation a.
The third line contains n distinct integers b1,b2,…,bn (1≤bi≤n) — the permutation b.
The fourth line contains n integers p0,p1,…,pn−1 (0≤pi≤109) — the sequence p.
Each of the next m lines contains an operation in one of the following formats:
- 1 l r k (0≤l<r≤n+1,1≤k≤n) — Output the maximum number of consecutive 1s in f((l,r),k).
- 2 x y (0≤x<n, 0≤y≤109) — Assign y to px.
It is guaranteed that the sums of n and m over all test cases do not exceed 4⋅105, respectively.
每个测试包含多个测试用例。第一行包含测试用例数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 m(1≤n,m≤2⋅105)—— 分别表示排列的长度与操作次数。
第二行包含 n 个互不相同的整数 a1,a2,…,an(1≤ai≤n)—— 排列 a。
第三行包含 n 个互不相同的整数 b1,b2,…,bn(1≤bi≤n)—— 排列 b。
第四行包含 n 个整数 p0,p1,…,pn−1(0≤pi≤109)—— 序列 p。
接下来的 m 行中,每行描述一个操作,格式为以下之一:
1 l r k(0≤l<r≤n+1, 1≤k≤n)—— 输出 f((l,r),k) 中连续1的最大个数。2 x y(0≤x<n, 0≤y≤109)—— 将 px 赋值为 y。
保证所有测试用例中 n 的总和与 m 的总和分别不超过 4⋅105。
输出格式
For each operation of type 1, output the answer in one line.
对于每个类型为 1 的操作,在一行中输出答案。
输入输出样例
输入#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]+[ ]→2
- f((1,4),2)=g(1,4)+f((2,3),1)=[1,1,1]+[ ]→3
- f((3,6),1)=g(3,6)+f((4,5),0)=[1,1,1,1,1]+[ ]→5
- f((0,6),2)=g(0,6)+f((3,4),1)=[1,1]+[ ]→2
In the second test case:
- f((2,5),1)=g(2,5)+f((3,4),0)=[0]+[ ]→0
- f((4,6),2)=g(4,6)+f((5,5),1)=[0]+[ ]→0
- f((0,5),1)=g(0,5)+f((2,2),0)=[0]+[ ]→0
- f((3,5),2)=g(3,5)+f((4,4),1)=[1,1,1]+[ ]→3
在第一个测试用例中:
- f((0,4),1)=g(0,4)+f((2,3),0)=[1,1]+[ ]→2
- f((1,4),2)=g(1,4)+f((2,3),1)=[1,1,1]+[ ]→3
- f((3,6),1)=g(3,6)+f((4,5),0)=[1,1,1,1,1]+[ ]→5
- f((0,6),2)=g(0,6)+f((3,4),1)=[1,1]+[ ]→2
在第二个测试用例中:
- f((2,5),1)=g(2,5)+f((3,4),0)=[0]+[ ]→0
- f((4,6),2)=g(4,6)+f((5,5),1)=[0]+[ ]→0
- f((0,5),1)=g(0,5)+f((2,2),0)=[0]+[ ]→0
- f((3,5),2)=g(3,5)+f((4,4),1)=[1,1,1]+[ ]→3
输入解题思路,AI测评打分。不知道怎么写?