CF1924B.Space Harbour

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are nn points numbered 11 to nn on a straight line. Initially, there are mm harbours. The ii-th harbour is at point XiX_i and has a value ViV_i. It is guaranteed that there are harbours at the points 11 and nn. There is exactly one ship on each of the nn points. The cost of moving a ship from its current location to the next harbour is the product of the value of the nearest harbour to its left and the distance from the nearest harbour to its right. Specifically, if a ship is already at a harbour, the cost of moving it to the next harbour is 00.

Additionally, there are qq queries, each of which is either of the following 22 types:

  • 11 xx vv — Add a harbour at point xx with value vv. It is guaranteed that before adding the harbour, there is no harbour at point xx.
  • 22 ll rr — Print the sum of the cost of moving all ships at points from ll to rr to their next harbours. Note that you just need to calculate the cost of moving the ships but not actually move them.

一条直线上有编号为 11 到 nn 的 nn 个点。初始时有 mm 个港口。第 ii 个港口位于点 XiX_i,其值为 ViV_i。保证点 11 和点 nn 处均设有港口。每个点上恰好停泊一艘船。

将一艘船从其当前位置移动到下一个港口的代价,定义为:其左侧最近港口的值 与 其右侧最近港口的距离 的乘积。特别地,若一艘船当前已位于某个港口,则将其移动到下一个港口的代价为 00。

此外,还有 qq 个查询,每个查询属于以下两种类型之一:

  • 1 x v — 在点 xx 新增一个值为 vv 的港口。保证在添加前点 xx 上没有港口。
  • 2 l r — 输出所有位于区间 [l,r][l, r] 内各点上的船,分别移动到各自下一个港口所需代价的总和。注意:你只需计算移动代价,而无需实际移动船只。

输入格式

The first line contains three integers nn, mm, and qq (2≤m≤n≤3⋅1052 \le m \le n \le 3 \cdot 10^5, 1≤q≤3⋅1051 \le q \le 3 \cdot 10^5) — the number of points, harbours, and queries, respectively.

The second line contains mm distinct integers X1,X2,…,Xm(1≤Xi≤n)X_1, X_2, \ldots, X_m(1 \le X_i \le n) — the position at which the ii-th harbour is located.

The third line contains mm integers V1,V2,…,Vm(1≤Vi≤107)V_1, V_2, \ldots, V_m(1 \le V_i \le 10^7) — the value of the ii-th harbour.

Each of the next qq lines contains three integers. The first integer is tt (1≤t≤21\le t \le 2) — type of query. If t=1t=1, then the next two integers are xx and vv (2≤x≤n−12 \le x \le n - 1, 1≤v≤1071 \le v \le 10^7) — first-type query. If t=2t=2, then the next two integers are ll and rr (1≤l≤r≤n1 \le l \le r \le n) — second-type query.

It is guaranteed that there is at least one second-type query.

第一行包含三个整数 nn、mm 和 qq(2≤m≤n≤3⋅1052 \le m \le n \le 3 \cdot 10^5,1≤q≤3⋅1051 \le q \le 3 \cdot 10^5),分别表示点的数量、港口的数量以及查询的数量。

第二行包含 mm 个互不相同的整数 X1,X2,…,XmX_1, X_2, \ldots, X_m(1≤Xi≤n1 \le X_i \le n),表示第 ii 个港口所在的位置。

第三行包含 mm 个整数 V1,V2,…,VmV_1, V_2, \ldots, V_m(1≤Vi≤1071 \le V_i \le 10^7),表示第 ii 个港口的值。

接下来的 qq 行每行包含三个整数。第一个整数为 tt(1≤t≤21\le t \le 2),表示查询类型。若 t=1t=1,则后两个整数为 xx 和 vv(2≤x≤n−12 \le x \le n - 1,1≤v≤1071 \le v \le 10^7),表示第一类查询;若 t=2t=2,则后两个整数为 ll 和 rr(1≤l≤r≤n1 \le l \le r \le n),表示第二类查询。

保证至少存在一个第二类查询。

输出格式

For every second-type query, print one integer in a new line — answer to this query.

对于每个第二类查询,在新的一行中输出一个整数——该查询的答案。

输入输出样例

  • 输入#1

    8 3 4
    1 3 8
    3 24 10
    2 2 5
    1 5 15
    2 5 5
    2 7 8

    输出#1

    171
    0
    15

说明/提示

For the first type 22 query, the cost for ships at positions 22, 33, 44 and 55 are 3(3×1)3(3 \times 1), 00, 96(24×4)96(24 \times 4) and 72(24×3)72(24 \times 3) respectively.

For the second type 22 query, since the ship at position 55 is already at a harbour, so the cost is 00.

For the third type 22 query, the cost for ships at position 77 and 88 are 15(15×1)15(15 \times 1) and 00 respectively.

对于第一个类型 2 的查询,位置 2、3、4 和 5 处的船只费用分别为 3(3×1)3(3 \times 1)、00、96(24×4)96(24 \times 4) 和 72(24×3)72(24 \times 3)。

对于第二个类型 2 的查询,由于位置 5 处的船只已位于港口,因此费用为 00。

对于第三个类型 2 的查询,位置 7 和 8 处的船只费用分别为 15(15×1)15(15 \times 1) 和 00。

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

首页