CF1919F1.Wine Factory (Easy Version)

提高+/省选-

通过率:0%

时间限制:5.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

This is the easy version of the problem. The only difference between the two versions is the constraint on cic_i and zz. You can make hacks only if both versions of the problem are solved.

There are three arrays aa, bb and cc. aa and bb have length nn and cc has length n−1n-1. Let W(a,b,c)W(a,b,c) denote the liters of wine created from the following process.

Create nn water towers. The ii-th water tower initially has aia_i liters of water and has a wizard with power bib_i in front of it. Furthermore, for each 1≤i≤n−11 \le i \le n - 1, there is a valve connecting water tower ii to i+1i + 1 with capacity cic_i.

For each ii from 11 to nn in this order, the following happens:

  1. The wizard in front of water tower ii removes at most bib_i liters of water from the tower and turns the removed water into wine.
  2. If i≠ni \neq n, at most cic_i liters of the remaining water left in water tower ii flows through the valve into water tower i+1i + 1.

There are qq updates. In each update, you will be given integers pp, xx, yy and zz and you will update ap:=xa_p := x, bp:=yb_p := y and cp:=zc_p := z. After each update, find the value of W(a,b,c)W(a,b,c). Note that previous updates to arrays aa, bb and cc persist throughout future updates.

这是该问题的简单版本。两个版本之间的唯一区别在于对 cic_i 和 zz 的约束条件。仅当两个版本的问题均被解决时,才允许进行 Hack。

给定三个数组 aa、bb 和 cc,其中 aa 和 bb 的长度为 nn,而 cc 的长度为 n−1n-1。记 W(a,b,c)W(a,b,c) 为通过以下过程所生成的葡萄酒(单位:升)总量。

构建 nn 座水塔。第 ii 座水塔初始含有 aia_i 升水,且其前方有一位法力值为 bib_i 的巫师。此外,对每个 1≤i≤n−11 \le i \le n - 1,在第 ii 座与第 i+1i + 1 座水塔之间设有一个容量为 cic_i 的阀门。

按 i=1,2,…,ni = 1, 2, \dots, n 的顺序,依次对每座水塔执行如下操作:

  1. 第 ii 座水塔前方的巫师最多从该塔中移除 bib_i 升水,并将所移除的水全部转化为葡萄酒;
  2. 若 i≠ni \neq n,则第 ii 座水塔中剩余的水最多有 cic_i 升经由阀门流入第 i+1i + 1 座水塔。

共有 qq 次更新操作。每次更新给出整数 pp、xx、yy 和 zz,并将 ap:=xa_p := x、bp:=yb_p := y、cp:=zc_p := z。每次更新后,请计算并输出 W(a,b,c)W(a,b,c) 的值。注意:对数组 aa、bb 和 cc 所做的先前更新会持续生效,影响后续所有更新。

输入格式

The first line contains two integers nn and qq (2≤n≤5⋅1052 \le n \le 5\cdot 10^5, 1≤q≤5⋅1051 \le q \le 5\cdot 10^5) — the number of water towers and the number of updates.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1090 \le a_i \le 10^9) — the number of liters of water in water tower ii.

The third line contains nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (0≤bi≤1090 \le b_i \le 10^9) — the power of the wizard in front of water tower ii.

The fourth line contains n−1n - 1 integers c1,c2,…,cn−1c_1, c_2, \ldots, c_{n - 1} (ci=1018c_i \color{red}{=} 10^{18}) — the capacity of the pipe connecting water tower ii to i+1i + 1.

Each of the next qq lines contains four integers pp, xx, yy and zz (1≤p≤n1 \le p \le n, 0≤x,y≤1090 \le x, y \le 10^9, z=1018z \color{red}{=} 10^{18}) — the updates done to arrays aa, bb and cc.

Note that cnc_n does not exist, so the value of zz does not matter when p=np = n.

第一行包含两个整数 nn 和 qq(2≤n≤5⋅1052 \le n \le 5\cdot 10^5,1≤q≤5⋅1051 \le q \le 5\cdot 10^5)—— 分别表示水塔的数量和更新操作的次数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤1090 \le a_i \le 10^9)—— 表示第 ii 个水塔中所含的水量(单位:升)。

第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(0≤bi≤1090 \le b_i \le 10^9)—— 表示位于第 ii 个水塔前方的巫师的法力值。

第四行包含 n−1n - 1 个整数 c1,c2,…,cn−1c_1, c_2, \ldots, c_{n - 1}(ci=1018c_i \color{red}{=} 10^{18})—— 表示连接第 ii 个水塔与第 i+1i + 1 个水塔的管道的容量。

接下来的 qq 行中,每行包含四个整数 pp、xx、yy 和 zz(1≤p≤n1 \le p \le n,0≤x,y≤1090 \le x, y \le 10^9,z=1018z \color{red}{=} 10^{18})—— 表示对数组 aa、bb 和 cc 所做的更新操作。

注意:cnc_n 不存在,因此当 p=np = n 时,zz 的值无关紧要。

输出格式

Print qq lines, each line containing a single integer representing W(a,b,c)W(a, b, c) after each update.

输出 qq 行,每行包含一个整数,表示每次更新后的 W(a,b,c)W(a, b, c) 值。

输入输出样例

  • 输入#1

    4 3
    3 3 3 3
    1 4 2 8
    1000000000000000000 1000000000000000000 1000000000000000000
    4 3 8 1000000000000000000
    2 5 1 1000000000000000000
    3 0 0 1000000000000000000

    输出#1

    12
    12
    10
  • 输入#2

    5 5
    10 3 8 9 2
    3 4 10 8 1
    1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000
    5 4 9 1000000000000000000
    1 1 1 1000000000000000000
    2 7 4 1000000000000000000
    4 1 1 1000000000000000000
    1 8 3 1000000000000000000

    输出#2

    34
    25
    29
    21
    27

说明/提示

The first update does not make any modifications to the arrays.

  • When i=1i = 1, there are 33 liters of water in tower 1 and 11 liter of water is turned into wine. The remaining 22 liters of water flow into tower 2.
  • When i=2i = 2, there are 55 liters of water in tower 2 and 44 liters of water is turned into wine. The remaining 11 liter of water flows into tower 3.
  • When i=3i = 3, there are 44 liters of water in tower 3 and 22 liters of water is turned into wine. The remaining 22 liters of water flows into tower 4.
  • When i=4i = 4, there are 55 liters of water in tower 4. All 55 liters of water are turned into wine.

Hence, W(a,b,c)=1+4+2+5=12W(a,b,c)=1 + 4 + 2 + 5 = 12 after the first update.

The second update modifies the arrays to a=[3,5,3,3]a = [3, 5, 3, 3], b=[1,1,2,8]b = [1, 1, 2, 8], and c=[1018,1018,1018]c = [10^{18}, 10^{18}, 10^{18}].

  • When i=1i = 1, there are 33 liters of water in tower 1 and 11 liter of water is turned into wine. The remaining 22 liters of water flow into tower 2.
  • When i=2i = 2, there are 77 liters of water in tower 2 and 11 liter of water is turned into wine. The remaining 66 liters of water flow into tower 3.
  • When i=3i = 3, there are 99 liters of water in tower 3 and 22 liters of water is turned into wine. The remaining 77 liters of water flow into tower 4.
  • When i=4i = 4, there are 1010 liters of water in tower 4. Only 88 liters of water is turned into wine.

Hence, W(a,b,c)=1+1+2+8=12W(a,b,c)=1 + 1 + 2 + 8 = 12 after the second update.

The third update modifies the arrays to a=[3,5,0,3]a = [3, 5, 0, 3], b=[1,1,0,8]b = [1, 1, 0, 8], and c=[1018,1018,1018]c = [10^{18}, 10^{18}, 10^{18}].

  • When i=1i = 1, there are 33 liters of water in tower 1 and 11 liter of water is turned into wine. The remaining 22 liters of water flow into tower 2.
  • When i=2i = 2, there are 77 liters of water in tower 2 and 11 liter of water is turned into wine. The remaining 66 liters of water flow into tower 3.
  • When i=3i = 3, there are 66 liters of water in tower 3 and 00 liters of water is turned into wine. The remaining 66 liters of water flow into tower 4.
  • When i=4i = 4, there are 99 liters of water in tower 4. Only 88 liters of water is turned into wine.

Hence, W(a,b,c)=1+1+0+8=10W(a,b,c)=1 + 1 + 0 + 8 = 10 after the third update.

第一次更新不会对数组进行任何修改。

  • 当 i=1i = 1 时,塔 1 中有 3 升水,其中 1 升水被转化为酒。剩余的 2 升水流向塔 2。
  • 当 i=2i = 2 时,塔 2 中有 5 升水,其中 4 升水被转化为酒。剩余的 1 升水流向塔 3。
  • 当 i=3i = 3 时,塔 3 中有 4 升水,其中 2 升水被转化为酒。剩余的 2 升水流向塔 4。
  • 当 i=4i = 4 时,塔 4 中有 5 升水,全部 5 升水均被转化为酒。

因此,第一次更新后,W(a,b,c)=1+4+2+5=12W(a,b,c)=1 + 4 + 2 + 5 = 12。

第二次更新将数组修改为 a=[3,5,3,3]a = [3, 5, 3, 3],b=[1,1,2,8]b = [1, 1, 2, 8],以及 c=[1018,1018,1018]c = [10^{18}, 10^{18}, 10^{18}]。

  • 当 i=1i = 1 时,塔 1 中有 3 升水,其中 1 升水被转化为酒。剩余的 2 升水流向塔 2。
  • 当 i=2i = 2 时,塔 2 中有 7 升水,其中 1 升水被转化为酒。剩余的 6 升水流向塔 3。
  • 当 i=3i = 3 时,塔 3 中有 9 升水,其中 2 升水被转化为酒。剩余的 7 升水流向塔 4。
  • 当 i=4i = 4 时,塔 4 中有 10 升水,其中仅有 8 升水被转化为酒。

因此,第二次更新后,W(a,b,c)=1+1+2+8=12W(a,b,c)=1 + 1 + 2 + 8 = 12。

第三次更新将数组修改为 a=[3,5,0,3]a = [3, 5, 0, 3],b=[1,1,0,8]b = [1, 1, 0, 8],以及 c=[1018,1018,1018]c = [10^{18}, 10^{18}, 10^{18}]。

  • 当 i=1i = 1 时,塔 1 中有 3 升水,其中 1 升水被转化为酒。剩余的 2 升水流向塔 2。
  • 当 i=2i = 2 时,塔 2 中有 7 升水,其中 1 升水被转化为酒。剩余的 6 升水流向塔 3。
  • 当 i=3i = 3 时,塔 3 中有 6 升水,其中 0 升水被转化为酒。剩余的 6 升水流向塔 4。
  • 当 i=4i = 4 时,塔 4 中有 9 升水,其中仅有 8 升水被转化为酒。

因此,第三次更新后,W(a,b,c)=1+1+0+8=10W(a,b,c)=1 + 1 + 0 + 8 = 10。

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

首页