CF1495F.Squares

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn squares drawn from left to right on the floor. The ii -th square has three integers pi,ai,bip_i,a_i,b_i , written on it. The sequence p1,p2,,pnp_1,p_2,\dots,p_n forms a permutation.

Each round you will start from the leftmost square 11 and jump to the right. If you are now on the ii -th square, you can do one of the following two operations:

  1. Jump to the i+1i+1 -th square and pay the cost aia_i . If i=ni=n , then you can end the round and pay the cost aia_i .
  2. Jump to the jj -th square and pay the cost bib_i , where jj is the leftmost square that satisfies j>i,pj>pij > i, p_j > p_i . If there is no such jj then you can end the round and pay the cost bib_i .

There are qq rounds in the game. To make the game more difficult, you need to maintain a square set SS (initially it is empty). You must pass through these squares during the round (other squares can also be passed through). The square set SS for the ii -th round is obtained by adding or removing a square from the square set for the (i1)(i-1) -th round.

For each round find the minimum cost you should pay to end it.

输入格式

The first line contains two integers nn , qq ( 1n,q21051\le n,q\le 2 \cdot 10^5 ) — the number of squares and the number of rounds.

The second line contains nn distinct integers p1,p2,,pnp_1,p_2,\dots,p_n ( 1pin1\le p_i\le n ). It is guaranteed that the sequence p1,p2,,pnp_1,p_2,\dots,p_n forms a permutation.

The third line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n ( 109ai109-10^9\le a_i\le 10^9 ).

The fourth line contains nn integers b1,b2,,bnb_1,b_2,\dots,b_n ( 109bi109-10^9\le b_i\le 10^9 ).

Then qq lines follow, ii -th of them contains a single integer xix_i ( 1xin1\le x_i\le n ). If xix_i was in the set SS on the (i1)(i-1) -th round you should remove it, otherwise, you should add it.

输出格式

Print qq 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 TT 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}\{1\} . The path you can use is 13T1\to 3\to T and its cost is 66 .

In the second round of the first test, the set that you must pass through is {1,2}\{1,2\} . The path you can use is 123T1\to 2\to 3\to T and its cost is 88 .

首页