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

#DSU0000092. Giải đấu hiệp sĩ (Knight Tournament)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Giải đấu hiệp sĩ (Knight Tournament)

Knight Tournament

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn knights numbered from 11 to nn, all initially active. In each of the mm battles, every still-active knight whose number lies in [li,ri][l_i,r_i] participates. Knight xix_i wins and remains active; every other participating knight is eliminated. Each battle has at least two active participants, and the sequence is guaranteed valid. Determine the knight who eliminated each participant; the overall champion is never eliminated.

Input

The first line contains n,mn,m. Each following line contains li,ri,xil_i,r_i,x_i.

Output

Print nn integers: the ii-th is the index of the knight who eliminated knight ii, or 00 for the champion.

Subtasks

  • Subtask 1 (20 points): 2≤n≤352\le n\le 35, 1≤m≤341\le m\le 34, 1≤li<ri≤n1\le l_i<r_i\le n, li≤xi≤ril_i\le x_i\le r_i; at least two active knights participate per battle.
  • Subtask 2 (30 points): 2≤n≤2502\le n\le 250, 1≤m≤2491\le m\le 249, 1≤li<ri≤n1\le l_i<r_i\le n, li≤xi≤ril_i\le x_i\le r_i; at least two active knights participate per battle.
  • Subtask 3 (50 points): 2≤n≤3⋅1052\le n\le 3\cdot10^5, 1≤m≤3⋅1051\le m\le 3\cdot10^5, 1≤li<ri≤n1\le l_i<r_i\le n, li≤xi≤ril_i\le x_i\le r_i; all battles satisfy the guarantees.

Examples

Input

4 3
1 2 1
1 3 3
1 4 4

Output

3 1 4 0

Explanation

Knight 22 loses to 11, then 11 loses to 33, and finally 33 loses to 44.