PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000241. Đặt chỗ trên các chuyến bay (Corporate Flight Bookings)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Đặt chỗ trên các chuyến bay (Corporate Flight Bookings)

Corporate Flight Bookings

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

An airline operates nn flights, numbered consecutively from 11 to nn. There are mm booking records. Booking ii contains three integers fi,li,sif_i,l_i,s_i.

Booking ii reserves an additional sis_i seats on every flight numbered from fif_i through lil_i, inclusive. For example, reserving 1010 seats on flights 22 through 44 adds 1010 reservations to each of flights 22, 33, and 44; the 1010 seats are not divided among those flights.

After processing all bookings, determine the total reserved seats for each flight separately. A flight mentioned in no booking has result 00.

Input

  • The first line contains integers n,mn,m: the number of flights and the number of bookings.
  • Each of the next mm lines contains integers fi,li,sif_i,l_i,s_i: the first flight, last flight, and seats reserved on each flight in the inclusive range [fi,li][f_i,l_i].

Output

Print exactly nn space-separated integers on one line. Value jj is the total seats reserved for flight jj.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 1≤m≤201\le m\le 20; 1≤fi≤li≤n1\le f_i\le l_i\le n and 1≤si≤1041\le s_i\le10^4 for every booking.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤m≤20001\le m\le 2000; 1≤fi≤li≤n1\le f_i\le l_i\le n and 1≤si≤1041\le s_i\le10^4 for every booking.
  • Subtask 3 (50 points): 1≤n≤200001\le n\le 20000; 1≤m≤200001\le m\le 20000; 1≤fi≤li≤n1\le f_i\le l_i\le n and 1≤si≤1041\le s_i\le10^4 for every booking.

Examples

Input

5 3
1 2 10
2 3 20
2 5 25

Output

10 55 45 25 25

Explanation

There are 55 flights and 33 bookings:

  • Booking (1,2,10)(1,2,10) produces [10,10,0,0,0][10,10,0,0,0].
  • Booking (2,3,20)(2,3,20) produces [10,30,20,0,0][10,30,20,0,0].
  • Booking (2,5,25)(2,5,25) produces [10,55,45,25,25][10,55,45,25,25].

Flight 22 has 10+20+25=5510+20+25=55 reserved seats; flight 33 has 20+25=4520+25=45. The other flight totals are 1010, 2525, and 2525.