CF1621B.Integers Shop

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The integers shop sells nn segments. The ii-th of them contains all integers from lil_i to rir_i and costs cic_i coins.

Tomorrow Vasya will go to this shop and will buy some segments there. He will get all integers that appear in at least one of bought segments. The total cost of the purchase is the sum of costs of all segments in it.

After shopping, Vasya will get some more integers as a gift. He will get integer xx as a gift if and only if all of the following conditions are satisfied:

  • Vasya hasn't bought xx.
  • Vasya has bought integer ll that is less than xx.
  • Vasya has bought integer rr that is greater than xx.

Vasya can get integer xx as a gift only once so he won't have the same integers after receiving a gift.

For example, if Vasya buys segment [2,4][2, 4] for 2020 coins and segment [7,8][7, 8] for 2222 coins, he spends 4242 coins and receives integers 2,3,4,7,82, 3, 4, 7, 8 from these segments. He also gets integers 55 and 66 as a gift.

Due to the technical issues only the first ss segments (that is, segments [l1,r1],[l2,r2],…,[ls,rs][l_1, r_1], [l_2, r_2], \ldots, [l_s, r_s]) will be available tomorrow in the shop.

Vasya wants to get (to buy or to get as a gift) as many integers as possible. If he can do this in differents ways, he selects the cheapest of them.

For each ss from 11 to nn, find how many coins will Vasya spend if only the first ss segments will be available.

整数商店出售 nn 个区间。其中第 ii 个区间包含从 lil_i 到 rir_i 的所有整数,售价为 cic_i 枚金币。

明天,瓦夏将前往该商店购买若干区间。他将获得所有在至少一个所购区间中出现的整数。此次购物的总花费等于所购所有区间的费用之和。

购物结束后,瓦夏还将额外获得一些整数作为赠品。当且仅当满足以下全部条件时,整数 xx 将作为赠品赠送给他:

  • 瓦夏未购买整数 xx;
  • 瓦夏购买了某个小于 xx 的整数 ll;
  • 瓦夏购买了某个大于 xx 的整数 rr。

每个整数 xx 最多仅能作为赠品获得一次,因此瓦夏不会因获赠而得到重复的整数。

例如,若瓦夏以 2020 枚金币购买区间 [2,4][2, 4],并以 2222 枚金币购买区间 [7,8][7, 8],则他共花费 4242 枚金币,并从这些区间中获得整数 2,3,4,7,82, 3, 4, 7, 8;此外,他还获得整数 55 和 66 作为赠品。

由于技术问题,明天商店中仅有前 ss 个区间(即区间 [l1,r1],[l2,r2],…,[ls,rs][l_1, r_1], [l_2, r_2], \ldots, [l_s, r_s])可供购买。

瓦夏希望尽可能多地获得整数(通过购买或获赠)。若存在多种方案可达成最大整数数量,则他选择其中总花费最小的方案。

对每个 ss(从 11 到 nn),求出当仅有前 ss 个区间可用时,瓦夏需要花费多少枚金币。

输入格式

The first line contains a single integer tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases.

The first line of each test case contains the single integer nn (1≤n≤1051 \leq n \leq 10^5) — the number of segments in the shop.

Each of next nn lines contains three integers lil_i, rir_i, cic_i (1≤li≤ri≤109,1≤ci≤1091 \leq l_i \leq r_i \leq 10^9, 1 \leq c_i \leq 10^9) — the ends of the ii-th segments and its cost.

It is guaranteed that the total sum of nn over all test cases doesn't exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000)——测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)——商店中线段的数量。

接下来的 nn 行中,每行包含三个整数 lil_i、rir_i、cic_i(1≤li≤ri≤1091 \leq l_i \leq r_i \leq 10^9,1≤ci≤1091 \leq c_i \leq 10^9)——第 ii 条线段的左右端点及其花费。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case output nn integers: the ss-th (1≤s≤n1 \leq s \leq n) of them should be the number of coins Vasia will spend in the shop if only the first ss segments will be available.

对于每个测试用例,输出 nn 个整数:其中第 ss 个整数(1≤s≤n1 \leq s \leq n)表示当仅有前 ss 个线段可用时,Vasia 在商店中将花费的硬币数量。

输入输出样例

  • 输入#1

    3
    2
    2 4 20
    7 8 22
    2
    5 11 42
    5 11 42
    6
    1 4 4
    5 8 9
    7 8 7
    2 10 252
    1 11 271
    1 10 1

    输出#1

    20
    42
    42
    42
    4
    13
    11
    256
    271
    271

说明/提示

In the first test case if s=1s = 1 then Vasya can buy only the segment [2,4][2, 4] for 2020 coins and get 33 integers.

The way to get 77 integers for 4242 coins in case s=2s = 2 is described in the statement.

In the second test case note, that there can be the same segments in the shop.

在第一个测试用例中,若 s=1s = 1,则 Vasya 只能以 2020 枚硬币购买区间 [2,4][2, 4],从而获得 33 个整数。

当 s=2s = 2 时,以 4242 枚硬币获得 77 个整数的方法已在题目描述中给出。

在第二个测试用例中,请注意商店中可能出现相同的区间。

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

首页