CF1515I.Phoenix and Diamonds

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

Phoenix wonders what it is like to rob diamonds from a jewelry store!

There are nn types of diamonds. The ii-th type has weight wiw_i and value viv_i. The store initially has aia_i diamonds of the ii-th type.

Each day, for qq days, one of the following will happen:

  1. A new shipment of kik_i diamonds of type did_i arrive.
  2. The store sells kik_i diamonds of type did_i.
  3. Phoenix wonders what will happen if he robs the store using a bag that can fit diamonds with total weight not exceeding cic_i. If he greedily takes diamonds of the largest value that fit, how much value would be taken? If there are multiple diamonds with the largest value, he will take the one with minimum weight. If, of the diamonds with the largest value, there are multiple with the same minimum weight, he will take any of them.

Of course, since Phoenix is a law-abiding citizen, this is all a thought experiment and he never actually robs any diamonds from the store. This means that queries of type 33 do not affect the diamonds in the store.

凤凰好奇,抢劫珠宝店的钻石会是什么感觉!

共有 nn 种钻石。第 ii 种钻石的重量为 wiw_i,价值为 viv_i。商店初始时拥有第 ii 种钻石 aia_i 颗。

接下来共 qq 天,每天会发生以下三种事件之一:

  1. 新到一批 kik_i 颗第 did_i 种钻石;
  2. 店铺售出 kik_i 颗第 did_i 种钻石;
  3. 凤凰思考:若他用一个承重上限为 cic_i 的背包去“抢劫”该店,且采用贪心策略——每次优先选取价值最大、同时仍能装入背包的钻石;当存在多个价值最大的钻石时,选择其中重量最小的一个;若仍有多个钻石满足“价值最大且重量最小”,则任选其一——那么最终能获得的总价值是多少?

当然,由于凤凰是一名遵纪守法的好公民,这仅是一场思想实验,他绝不会真正从店里抢劫任何钻石。这意味着类型 33 的查询不会改变店内钻石的数量。

输入格式

The first line contains two integers nn and qq (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5; 1≤q≤1051 \le q \le 10^5) — the number of types of diamonds and number of days, respectively.

The next nn lines describe each type of diamond. The ii-th line will contain three integers aia_i, wiw_i, and viv_i (0≤ai≤1050 \le a_i \le 10^5; 1≤wi,vi≤1051 \le w_i, v_i \le 10^5) — the initial number of diamonds of the ii-th type, the weight of diamonds of the ii-th type, and the value of diamonds of the ii-th type, respectively.

The next qq lines contain the queries. For each query, the first integer of each line is tt (1≤t≤31 \le t \le 3) — the type of query.

If t=1t=1, then two integers kik_i, did_i follow (1≤ki≤1051 \le k_i \le 10^5; 1≤di≤n1 \le d_i \le n). This means that a new shipment of kik_i diamonds arrived, each of type did_i.

If t=2t=2, then two integers kik_i, did_i follow (1≤ki≤1051 \le k_i \le 10^5; 1≤di≤n1 \le d_i \le n). This means that the store has sold kik_i diamonds, each of type did_i. It is guaranteed that the store had the diamonds before they sold them.

If t=3t=3, an integer cic_i will follow (1≤ci≤10181 \le c_i \le 10^{18}) — the weight capacity of Phoenix's bag.

It is guaranteed that there is at least one query where t=3t=3.

第一行包含两个整数 nn 和 qq(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5;1≤q≤1051 \le q \le 10^5),分别表示钻石类型的数量和天数。

接下来的 nn 行描述每种钻石。第 ii 行包含三个整数 aia_i、wiw_i 和 viv_i(0≤ai≤1050 \le a_i \le 10^5;1≤wi,vi≤1051 \le w_i, v_i \le 10^5),分别表示第 ii 种钻石的初始数量、单颗重量以及单颗价值。

接下来的 qq 行为查询。对每个查询,每行的第一个整数为 tt(1≤t≤31 \le t \le 3),表示查询类型。

若 t=1t=1,则随后跟两个整数 kik_i、did_i(1≤ki≤1051 \le k_i \le 10^5;1≤di≤n1 \le d_i \le n)。这表示新到一批 kik_i 颗钻石,均为第 did_i 种类型。

若 t=2t=2,则随后跟两个整数 kik_i、did_i(1≤ki≤1051 \le k_i \le 10^5;1≤di≤n1 \le d_i \le n)。这表示商店售出了 kik_i 颗钻石,均为第 did_i 种类型。保证售出前商店拥有足够数量的该类型钻石。

若 t=3t=3,则随后跟一个整数 cic_i(1≤ci≤10181 \le c_i \le 10^{18}),表示凤凰背包的重量容量。

保证至少存在一个满足 t=3t=3 的查询。

输出格式

Print the answer for each query of the third type (t=3t=3).

输出每个第三类查询(t=3t=3)的答案。

输入输出样例

  • 输入#1

    3 5
    2 3 4
    1 5 1
    0 2 4
    3 6
    1 3 3
    3 10
    2 2 3
    3 30

    输出#1

    8
    16
    13

说明/提示

For the first query where t=3t=3, Phoenix can fit 22 diamonds of type 11, with total weight 66 and value 88.

For the second query where t=3t=3, Phoenix will first fit in 33 diamonds of type 33, then one diamond of type 11 for a total weight of 99 and a value of 1616. Note that diamonds of type 33 are prioritized over type 11 because type 33 has equal value but less weight.

For the final query where t=3t=3, Phoenix can fit every diamond for a total value of 1313.

对于第一个查询(t=3t=3),凤凰可以装入 22 颗类型 11 的钻石,总重量为 66,总价值为 88。

对于第二个查询(t=3t=3),凤凰将首先装入 33 颗类型 33 的钻石,再装入 11 颗类型 11 的钻石,总重量为 99,总价值为 1616。注意:类型 33 的钻石优先于类型 11 的钻石,因为它们的价值相同但重量更小。

对于最后一个查询(t=3t=3),凤凰可以装入所有钻石,总价值为 1313。

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

首页