CF1495F.Squares
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n squares drawn from left to right on the floor. The i -th square has three integers pi,ai,bi , written on it. The sequence p1,p2,…,pn forms a permutation.
Each round you will start from the leftmost square 1 and jump to the right. If you are now on the i -th square, you can do one of the following two operations:
- Jump to the i+1 -th square and pay the cost ai . If i=n , then you can end the round and pay the cost ai .
- Jump to the j -th square and pay the cost bi , where j is the leftmost square that satisfies j>i,pj>pi . If there is no such j then you can end the round and pay the cost bi .
There are q rounds in the game. To make the game more difficult, you need to maintain a square set S (initially it is empty). You must pass through these squares during the round (other squares can also be passed through). The square set S for the i -th round is obtained by adding or removing a square from the square set for the (i−1) -th round.
For each round find the minimum cost you should pay to end it.
输入格式
The first line contains two integers n , q ( 1≤n,q≤2⋅105 ) — the number of squares and the number of rounds.
The second line contains n distinct integers p1,p2,…,pn ( 1≤pi≤n ). It is guaranteed that the sequence p1,p2,…,pn forms a permutation.
The third line contains n integers a1,a2,…,an ( −109≤ai≤109 ).
The fourth line contains n integers b1,b2,…,bn ( −109≤bi≤109 ).
Then q lines follow, i -th of them contains a single integer xi ( 1≤xi≤n ). If xi was in the set S on the (i−1) -th round you should remove it, otherwise, you should add it.
输出格式
Print q lines, each of them should contain a single integer — the minimum cost you should pay to end the corresponding round.
输入输出样例
输入#1
3 2 2 1 3 10 -5 4 3 -2 3 1 2
输出#1
6 8
输入#2
5 4 2 1 5 3 4 6 -5 3 -10 -1 0 3 2 7 2 1 2 3 2
输出#2
-8 -7 -7 -8
说明/提示
Let's consider the character T as the end of a round. Then we can draw two graphs for the first and the second test.
In the first round of the first test, the set that you must pass through is {1} . The path you can use is 1→3→T and its cost is 6 .
In the second round of the first test, the set that you must pass through is {1,2} . The path you can use is 1→2→3→T and its cost is 8 .