CF1804G.Flow Control

NOI/NOI+/CTSC

通过率:0%

时间限制:6.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Raj has a single physical network line that connects his office to the Internet. This line bandwidth is bb bytes per millisecond.

There are nn users who would like to use this network line to transmit some data. The ii-th of them will use the line from millisecond sis_i to millisecond fif_i inclusive. His initial data rate will be set to did_i. That means he will use data rate equal to did_i for millisecond sis_i, and then it will change according to the procedure described below.

The flow control will happen as follows. Suppose there are mm users trying to transmit some data via the given network line during millisecond xx. Denote as tit_i the data rate that the ii-th of these mm users has at the beginning of this millisecond. All tit_i are non-negative integer values.

  1. If m=0m = 0, i. e. there are no users trying to transmit data during this millisecond, nothing happens.
  2. If the sum of all tit_i is less than or equal to bb, each active user successfully completes his transmission (the ii-th active user transmits tit_i bytes). After that, the data rate of each active user grows by 11, i. e. each tit_i is increased by 11.
  3. If the sum of all tit_i is greater than bb, the congestion occurs and no data transmissions succeed this millisecond at all. If that happens, each tit_i decreases twice, i. e. each tit_i is replaced with ⌊ti2⌋\lfloor \frac{t_i}{2} \rfloor.

Raj knows all the values nn, bb, sis_i, fif_i, and did_i, he wants to calculate the total number of bytes transmitted by all the users in the aggregate.

拉吉拥有一条连接其办公室与互联网的物理网络线路。该线路的带宽为 bb 字节/毫秒。

共有 nn 个用户希望使用该网络线路传输数据。其中第 ii 个用户将在毫秒 sis_i 至毫秒 fif_i(含端点)期间使用该线路。其初始数据速率为 did_i,即:在毫秒 sis_i 时,其数据速率被设为 did_i;此后,该速率将按如下所述规则变化。

流量控制过程如下:假设在毫秒 xx 期间,有 mm 个用户试图通过该网络线路传输数据。记这 mm 个用户在该毫秒开始时的数据速率分别为 tit_i(i=1,2,…,mi = 1, 2, \dots, m)。所有 tit_i 均为非负整数。

  1. 若 m=0m = 0,即该毫秒内无用户尝试传输数据,则不发生任何操作。
  2. 若所有 tit_i 的总和小于或等于 bb,则每个活跃用户均成功完成本次传输(第 ii 个活跃用户传输 tit_i 字节)。此后,每个活跃用户的数据速率增加 11,即每个 tit_i 均加 11。
  3. 若所有 tit_i 的总和大于 bb,则发生拥塞,该毫秒内所有数据传输均失败。此时,每个 tit_i 减半(向下取整),即每个 tit_i 被替换为 ⌊ti2⌋\lfloor \frac{t_i}{2} \rfloor。

拉吉已知所有参数 nn、bb、sis_i、fif_i 和 did_i,他希望计算所有用户传输的字节总数。

输入格式

The first line of the input contains two integers nn and bb (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5, 1≤b≤1091 \leq b \leq 10^9), the number of users who will use the line and the line bandwidth, respectively.

Each of the following nn lines contains three integers sis_i, fif_i and did_i (1≤si≤fi≤1091 \leq s_i \leq f_i \leq 10^9, 1≤di≤1091 \leq d_i \leq 10^9), denoting that the ii-th user will try to transmit data during each millisecond between sis_i and fif_i inclusive, and the initial data rate of the ii-th user.

输入的第一行包含两个整数 nn 和 bb(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5,1≤b≤1091 \leq b \leq 10^9),分别表示将使用该线路的用户数量和线路带宽。

接下来的 nn 行中,每行包含三个整数 sis_i、fif_i 和 did_i(1≤si≤fi≤1091 \leq s_i \leq f_i \leq 10^9,1≤di≤1091 \leq d_i \leq 10^9),表示第 ii 个用户将在每个介于 sis_i 与 fif_i(含端点)之间的毫秒时刻尝试传输数据,且第 ii 个用户的初始数据传输速率为 did_i。

输出格式

Print one integer — the total number of bytes all users will successfully transmit.

输出一个整数——所有用户成功传输的字节数总和。

输入输出样例

  • 输入#1

    1 3
    1 5 2

    输出#1

    10
  • 输入#2

    1 10
    7 11 1000

    输出#2

    0
  • 输入#3

    2 6
    1 12 1
    8 20 3

    输出#3

    64
  • 输入#4

    3 10
    1 100 1
    30 60 20
    40 80 6

    输出#4

    534

说明/提示

Consider the first example.

  • Millisecond 11: User 11 transmits 22 bytes.
  • Millisecond 22: User 11 transmits 33 bytes.
  • Millisecond 33: Congestion occurs, and no user transmits data.
  • Millisecond 44: User 11 transmits 22 bytes.
  • Millisecond 55: User 11 transmits 33 bytes.

In the second example, at each millisecond from the 77-th to the 1111-th inclusive, congestion occurs, and the only user decreases their rate twice. However, they don't decrease the speed enough before disconnecting.

Consider the third example.

  • Millisecond 11: User 11 transmits 11 bytes.
  • Millisecond 22: User 11 transmits 22 bytes.
  • Millisecond 33: User 11 transmits 33 bytes.
  • Millisecond 44: User 11 transmits 44 bytes.
  • Millisecond 55: User 11 transmits 55 bytes.
  • Millisecond 66: User 11 transmits 66 bytes.
  • Millisecond 77: Congestion occurs, and no user transmits data.
  • Millisecond 88: User 11 transmits 33 bytes. User 22 transmits 33 bytes.
  • Millisecond 99: Congestion occurs, and no user transmits data.
  • Millisecond 1010: User 11 transmits 22 bytes. User 22 transmits 22 bytes.
  • Millisecond 1111: User 11 transmits 33 bytes. User 22 transmits 33 bytes.
  • Millisecond 1212: Congestion occurs, and no user transmits data.
  • Millisecond 1313: User 22 transmits 22 bytes.
  • Millisecond 1414: User 22 transmits 33 bytes.
  • Millisecond 1515: User 22 transmits 44 bytes.
  • Millisecond 1616: User 22 transmits 55 bytes.
  • Millisecond 1717: User 22 transmits 66 bytes.
  • Millisecond 1818: Congestion occurs, and no user transmits data.
  • Millisecond 1919: User 22 transmits 33 bytes.
  • Millisecond 2020: User 22 transmits 44 bytes.

考虑第一个例子。

  • 第 1 毫秒:用户 11 传输 22 字节。
  • 第 2 毫秒:用户 11 传输 33 字节。
  • 第 3 毫秒:发生拥塞,无用户传输数据。
  • 第 4 毫秒:用户 11 传输 22 字节。
  • 第 5 毫秒:用户 11 传输 33 字节。

在第二个例子中,从第 77 毫秒到第 1111 毫秒(含)的每一毫秒均发生拥塞,且唯一用户将其传输速率降低了两次。然而,在断开连接前,其降速幅度仍不足。

考虑第三个例子。

  • 第 1 毫秒:用户 11 传输 11 字节。
  • 第 2 毫秒:用户 11 传输 22 字节。
  • 第 3 毫秒:用户 11 传输 33 字节。
  • 第 4 毫秒:用户 11 传输 44 字节。
  • 第 5 毫秒:用户 11 传输 55 字节。
  • 第 6 毫秒:用户 11 传输 66 字节。
  • 第 7 毫秒:发生拥塞,无用户传输数据。
  • 第 8 毫秒:用户 11 传输 33 字节,用户 22 传输 33 字节。
  • 第 9 毫秒:发生拥塞,无用户传输数据。
  • 第 10 毫秒:用户 11 传输 22 字节,用户 22 传输 22 字节。
  • 第 11 毫秒:用户 11 传输 33 字节,用户 22 传输 33 字节。
  • 第 12 毫秒:发生拥塞,无用户传输数据。
  • 第 13 毫秒:用户 22 传输 22 字节。
  • 第 14 毫秒:用户 22 传输 33 字节。
  • 第 15 毫秒:用户 22 传输 44 字节。
  • 第 16 毫秒:用户 22 传输 55 字节。
  • 第 17 毫秒:用户 22 传输 66 字节。
  • 第 18 毫秒:发生拥塞,无用户传输数据。
  • 第 19 毫秒:用户 22 传输 33 字节。
  • 第 20 毫秒:用户 22 传输 44 字节。

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

首页