#P9695. [GDCPC 2023] Traveling in Cells
[GDCPC 2023] 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