CF1495F.Squares

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

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 \gt i, p_j \gt 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 (i−1)(i-1)-th round.

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

地面上从左到右画有 nn 个方格。第 ii 个方格上写有三个整数 pi,ai,bip_i, a_i, b_i。序列 p1,p2,…,pnp_1, p_2, \dots, p_n 构成一个排列。

每轮游戏你都从最左侧的方格 11 出发,向右跳跃。若当前位于第 ii 个方格,则可执行以下两种操作之一:

  1. 跳至第 i+1i+1 个方格,并支付代价 aia_i;若 i=ni = n,则可直接结束本轮,并支付代价 aia_i。
  2. 跳至第 jj 个方格,并支付代价 bib_i,其中 jj 是满足 j>ij > i 且 pj>pip_j > p_i 的最小下标(即最靠左的满足条件的方格);若不存在这样的 jj,则可直接结束本轮,并支付代价 bib_i。

游戏共进行 qq 轮。为增加难度,你需要维护一个方格集合 SS(初始为空集)。在每轮中,你必须经过集合 SS 中的所有方格(也可经过其他方格)。第 ii 轮的方格集合 SS 是通过对第 i−1i-1 轮的集合 SS 添加或删除一个方格得到的。

对每一轮,请计算结束该轮所需的最小总代价。

输入格式

The first line contains two integers nn, qq (1≤n,q≤2⋅1051\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 (1≤pi≤n1\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 (−109≤ai≤109-10^9\le a_i\le 10^9).

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

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

第一行包含两个整数 nn、qq(1≤n,q≤2⋅1051\le n,q\le 2 \cdot 10^5)—— 分别表示方格的数量和轮数。

第二行包含 nn 个互不相同的整数 p1,p2,…,pnp_1,p_2,\dots,p_n(1≤pi≤n1\le p_i\le n)。保证序列 p1,p2,…,pnp_1,p_2,\dots,p_n 构成一个排列。

第三行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(−109≤ai≤109-10^9\le a_i\le 10^9)。

第四行包含 nn 个整数 b1,b2,…,bnb_1,b_2,\dots,b_n(−109≤bi≤109-10^9\le b_i\le 10^9)。

接下来是 qq 行,其中第 ii 行包含一个整数 xix_i(1≤xi≤n1\le x_i\le n)。若 xix_i 在第 (i−1)(i-1) 轮时属于集合 SS,则应将其移除;否则,应将其加入。

输出格式

Print qq lines, each of them should contain a single integer — the minimum cost you should pay to end the corresponding round.

输出 qq 行,每行应包含一个整数——即完成对应轮次所需的最小花费。

输入输出样例

  • 输入#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 1→3→T1\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 1→2→3→T1\to 2\to 3\to T and its cost is 88.

我们将字符 TT 视为一轮的终点。那么,我们可以为第一个和第二个测试分别绘制两张图。

在第一个测试的第一轮中,你必须经过的点集为 {1}\{1\}。你可以采用的路径是 1→3→T1\to 3\to T,其代价为 66。

在第一个测试的第二轮中,你必须经过的点集为 {1,2}\{1,2\}。你可以采用的路径是 1→2→3→T1\to 2\to 3\to T,其代价为 88。

输入解题思路,AI测评打分。不知道怎么写?

首页