#abc320e. E - Somen Nagashi

E - Somen Nagashi

Score : 475475 points

问题描述

NN 人在参加一个名为“流动面条”的活动。这些人排成一排,按照从前到后的顺序编号为 11NN

在活动期间,发生了 MM 次以下情况:

  • 在时间点 TiT_i,会有数量为 WiW_i 的面条从上而下飘落。排头的人会得到所有面条(如果队伍中无人,则没有人得到)。然后该人离开队伍,并在时间 Ti+SiT_i+S_i 返回到队伍中的原始位置。

在时间 XX 回到队伍的人被视为在时间 XX 处于队伍之中。

经历这 MM 次事件后,请报告每个人总共得到了多少面条。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN people gathered for an event called Flowing Noodles. The people are lined up in a row, numbered 11 to NN in order from front to back.

During the event, the following occurrence happens MM times:

  • At time TiT_i, a quantity WiW_i of noodles is flown down. The person at the front of the row gets all of it (if no one is in the row, no one gets it). That person then steps out of the row and returns to their original position in the row at time Ti+SiT_i+S_i.

A person who returns to the row at time XX is considered to be in the row at time XX.

After all the MM occurrences, report the total amount of noodles each person has got.

Constraints

  • 1N2×1051 \leq N \leq 2\times 10^5
  • 1M2×1051 \leq M \leq 2\times 10^5
  • 0<T1<<TM1090 <T_1 <\ldots < T_M \leq 10^9
  • 1Si1091 \leq S_i \leq 10^9
  • 1Wi1091 \leq W_i \leq 10^9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN MM

T1T_1 W1W_1 S1S_1

\vdots

TMT_M WMW_M SMS_M

Output

Print NN lines. The ii-th line should contain the amount of noodles person ii has got.

Sample Input 1

3 5
1 1 3
2 10 100
4 100 10000
10 1000 1000000000
100 1000000000 1

Sample Output 1

101
10
1000

The event proceeds as follows:

  • At time 11, a quantity 11 of noodles is flown down. People 11, 22, and 33 are in the row, and the person at the front, person 11, gets the noodles and steps out of the row.
  • At time 22, a quantity 1010 of noodles is flown down. People 22 and 33 are in the row, and the person at the front, person 22, gets the noodles and steps out of the row.
  • At time 44, person 11 returns to the row.
  • At time 44, a quantity 100100 of noodles is flown down. People 11 and 33 are in the row, and the person at the front, person 11, gets the noodles and steps out of the row.
  • At time 1010, a quantity 10001000 of noodles is flown down. Only person 33 is in the row, and the person at the front, person 33, gets the noodles and steps out of the row.
  • At time 100100, a quantity 10000000001000000000 of noodles is flown down. No one is in the row, so no one gets these noodles.
  • At time 102102, person 22 returns to the row.
  • At time 1000410004, person 11 returns to the row.
  • At time 10000000101000000010, person 33 returns to the row.

The total amounts of noodles people 11, 22, and 33 have got are 101101, 1010, and 10001000, respectively.

Sample Input 2

3 1
1 1 1

Sample Output 2

1
0
0

Sample Input 3

1 8
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
8 8 8

Sample Output 3

15

update @ 2024/3/10 01:38:52