#P9695. [GDCPC2023] Traveling in Cells
[GDCPC2023] Traveling in Cells
题目描述
There are cells arranged in a row. The -th cell has a color and contains a ball with value .
You're going to travel several times in the cells. For each travel, you'll be given an integer and a set of colors where . The travel starts from cell . During the travel, if you're located in cell you can next move to cell or . Note that you can't move out of these cells. Also at any time, the color of cell you're located in must belong to set .
When you're in cell , you can choose to remove the ball in the cell and gain its value . As there is only one ball in each cell, you can only remove the ball from each cell once.
Your task is to process operations in order. Each operation is one of the following three types:
- : Change to .
- : Change to .
- : Given the starting cell and the color set 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 indicating the number of test cases. For each test case:
The first line contains two integers and (, ) indicating the number of cells and the number of operations.
The second line contains integers () where is the initial color of the -th cell.
The third line contains integers () where is the initial value of ball in the -th cell.
For the following lines, the -th line describes the -th operation. The input format is listed as follows:
- : and .
- : and .
- : , and .
It's guaranteed that neither the sum of nor the sum of of all test cases will exceed . Also the sum of of all test cases will not exceed .
输出格式
For each operation of type output one line containing one integer, indicating the maximum total value you can gain.
题目大意
【题目描述】
有 个格子排成一行,第 个格子的颜色为 ,上面放置着一个权值为 的球。
您将要在格子中进行若干次旅行。每次旅行时,您会得到旅行的起点 与一个颜色集合 ,且保证 。旅行将从第 个格子上开始。在旅行期间,如果您在格子 处,那么您可以向格子 或 处移动,但不能移动到这 个格子之外。且在任意时刻,您所处的格子的颜色必须在集合 中。
当您位于格子 时,您可以选择将格子上的球取走,并获得 的权值。由于每个格子上只有一个球,因此一个格子上的球只能被取走一次。
您的任务是依次处理 次操作,每次操作形如以下三种操作之一:
- :将 修改为 。
- :将 修改为 。
- :给定旅行的起点 与一个颜色集合 。假设如果进行这样的一次旅行,求出取走的球的权值之和最大是多少。注意,由于我们仅仅假设进行一次旅行,因此并不会真的取走任何球。即,所有询问之间是独立的。
【输入格式】
有多组测试数据。第一行输入一个整数 表示测试数据组数。对于每组测试数据:
第一行输入两个整数 和 (,)表示格子的数量和操作的数量。
第二行输入 个整数 (),其中 表示第 个格子的初始颜色。
第三行输入 个整数 (),其中 表示第 个格子里的球的初始权值。
对于接下来 行,第 行描述第 次操作,格式如下:
- :保证 且 。
- :保证 且 。
- :保证 且 且 。
保证所有数据 之和与 之和均不超过 ,且所有数据 之和不超过 。
【输出格式】
对于每次操作 输出一行一个整数,表示取走的球的权值之和的最大值。
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