CF2223E Zhily and Permutation

Description

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 Format

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 Format

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

Explanation/Hint

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} $