luogu#P9695. [GDCPC2023] Traveling in Cells

[GDCPC2023] Traveling in Cells

题目描述

There are nn cells arranged in a row. The ii-th cell has a color cic_i and contains a ball with value viv_i.

You're going to travel several times in the cells. For each travel, you'll be given an integer xx and a set of colors A={a1,a2,,ak}\mathbb{A} = \{a_1, a_2, \cdots, a_k\} where cxAc_x \in \mathbb{A}. The travel starts from cell xx. During the travel, if you're located in cell ii you can next move to cell (i1)(i - 1) or (i+1)(i + 1). Note that you can't move out of these nn cells. Also at any time, the color of cell you're located in must belong to set A\mathbb{A}.

When you're in cell ii, you can choose to remove the ball in the cell and gain its value viv_i. As there is only one ball in each cell, you can only remove the ball from each cell once.

Your task is to process qq operations in order. Each operation is one of the following three types:

  • 1  p  x1\; p \; x: Change cpc_p to xx.
  • 2  p  x2\; p \; x: Change vpv_p to xx.
  • 3  x  k  a1  a2    ak3\; x\; k\; a_1\; a_2 \; \ldots\; a_k: Given the starting cell xx and the color set A={a1,a2,,ak}\mathbb{A} = \{a_1, a_2, \cdots, a_k\} of a travel, imagine that you're going on this travel, calculate the maximum total value you can gain. Note that this travel is only an imagination, thus the balls won't be truely removed. That is, all queries are independent.

输入格式

There are multiple test cases. The first line of the input contains an integer TT indicating the number of test cases. For each test case:

The first line contains two integers nn and qq (1n1051 \leq n \leq 10^5, 1q1051 \leq q \leq 10^5) indicating the number of cells and the number of operations.

The second line contains nn integers c1,c2,,cnc_1, c_2, \ldots, c_n (1cin1 \leq c_i \leq n) where cic_i is the initial color of the ii-th cell.

The third line contains nn integers v1,v2,,vnv_1, v_2, \ldots, v_n (1vi1091 \leq v_i \leq 10^9) where viv_i is the initial value of ball in the ii-th cell.

For the following qq lines, the ii-th line describes the ii-th operation. The input format is listed as follows:

  • 1  p  x1\; p\; x: 1pn1 \leq p \leq n and 1xn1 \leq x \leq n.
  • 2  p  x2\; p\; x: 1pn1 \leq p \leq n and 1x1091 \leq x \leq 10^9.
  • 3  x  k  a1  a2    ak3\; x\; k\; a_1\; a_2\; \ldots \; a_k: 1xn1 \leq x \leq n, 1a1<a2<<akn1 \leq a_1 < a_2 < \ldots < a_k \leq n and cx{a1,a2,,ak}c_x \in \{a_1, a_2, \cdots, a_k\}.

It's guaranteed that neither the sum of nn nor the sum of qq of all test cases will exceed 3×1053 \times 10^5. Also the sum of kk of all test cases will not exceed 10610^6.

输出格式

For each operation of type 33 output one line containing one integer, indicating the maximum total value you can gain.

题目大意

【题目描述】

nn 个格子排成一行,第 ii 个格子的颜色为 cic_i,上面放置着一个权值为 viv_i 的球。

您将要在格子中进行若干次旅行。每次旅行时,您会得到旅行的起点 xx 与一个颜色集合 A={a1,a2,,ak}\mathbb{A} = \{a_1, a_2, \cdots, a_k\},且保证 cxAc_x \in \mathbb{A}。旅行将从第 xx 个格子上开始。在旅行期间,如果您在格子 ii 处,那么您可以向格子 (i1)(i - 1)(i+1)(i + 1) 处移动,但不能移动到这 nn 个格子之外。且在任意时刻,您所处的格子的颜色必须在集合 A\mathbb{A} 中。

当您位于格子 ii 时,您可以选择将格子上的球取走,并获得 viv_i 的权值。由于每个格子上只有一个球,因此一个格子上的球只能被取走一次。

您的任务是依次处理 qq 次操作,每次操作形如以下三种操作之一:

  • 1  p  x1\; p \; x:将 cpc_p 修改为 xx
  • 2  p  x2\; p \; x:将 vpv_p 修改为 xx
  • 3  x  k  a1  a2    ak3\; x\; k\; a_1\; a_2 \; \ldots\; a_k:给定旅行的起点 xx 与一个颜色集合 A={a1,a2,,ak}\mathbb{A} = \{a_1, a_2, \cdots, a_k\}。假设如果进行这样的一次旅行,求出取走的球的权值之和最大是多少。注意,由于我们仅仅假设进行一次旅行,因此并不会真的取走任何球。即,所有询问之间是独立的。

【输入格式】

有多组测试数据。第一行输入一个整数 TT 表示测试数据组数。对于每组测试数据:

第一行输入两个整数 nnqq1n1051 \leq n \leq 10^51q1051 \leq q \leq 10^5)表示格子的数量和操作的数量。

第二行输入 nn 个整数 c1,c2,,cnc_1, c_2, \ldots, c_n1cin1 \leq c_i \leq n),其中 cic_i 表示第 ii 个格子的初始颜色。

第三行输入 nn 个整数 v1,v2,,vnv_1, v_2, \ldots, v_n1vi1091 \leq v_i \leq 10^9),其中 viv_i 表示第 ii 个格子里的球的初始权值。

对于接下来 qq 行,第 ii 行描述第 ii 次操作,格式如下:

  • 1  p  x1\; p\; x:保证 1pn1 \leq p \leq n1xn1 \leq x \leq n
  • 2  p  x2\; p\; x:保证 1pn1 \leq p \leq n1x1091 \leq x \leq 10^9
  • 3  x  k  a1  a2    ak3\; x\; k\; a_1\; a_2\; \ldots \; a_k:保证 1xn1 \leq x \leq n1a1<a2<<akn1 \leq a_1 < a_2 < \ldots < a_k \leq ncx{a1,a2,,ak}c_x \in \{a_1, a_2, \cdots, a_k\}

保证所有数据 nn 之和与 qq 之和均不超过 3×1053 \times 10^5,且所有数据 kk 之和不超过 10610^6

【输出格式】

对于每次操作 33 输出一行一个整数,表示取走的球的权值之和的最大值。

2
5 10
1 2 3 1 2
1 10 100 1000 10000
3 3 1 3
3 3 2 2 3
2 5 20000
2 3 200
3 3 2 1 3
3 3 3 1 2 3
1 3 4
2 1 100000
1 2 2
3 1 2 1 2
4 1
1 2 3 4
1000000 1000000 1000000 1000000
3 4 4 1 2 3 4
100
110
1200
21211
100010
4000000