Codeforces Round 207 (Div. 1)
A
Knight Tournament
Codeforces
1500
原题
←B →
翻译中…

Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.

翻译中…

As for you, you're just a simple peasant. There's no surprise that you slept in this morning and were late for the tournament (it was a weekend, after all). Now you are really curious about the results of the tournament. This time the tournament in Berland went as follows:

翻译中…
  • There are $*n*$ knights participating in the tournament. Each knight was assigned his unique number — an integer from 1 to $*n*$.
  • The tournament consisted of $*m*$ fights, in the $*i*$-th fight the knights that were still in the game with numbers at least $*l*_{*i*}$ and at most $*r*_{*i*}$ have fought for the right to continue taking part in the tournament.
  • After the $*i*$-th fight among all participants of the fight only one knight won — the knight number $*x*_{*i*}$, he continued participating in the tournament. Other knights left the tournament.
  • The winner of the last (the $*m*$-th) fight (the knight number $*x*_{*m*}$) became the winner of the tournament.
翻译中…

You fished out all the information about the fights from your friends. Now for each knight you want to know the name of the knight he was conquered by. We think that the knight number $*b*$ was conquered by the knight number $*a*$, if there was a fight with both of these knights present and the winner was the knight number $*a*$.

翻译中…

Write the code that calculates for each knight, the name of the knight that beat him.

翻译中…

Input

翻译中…

The first line contains two integers $*n*$, $*m*$ $(2 ≤ *n* ≤ 3·10^{5}; 1 ≤ *m* ≤ 3·10^{5})$ — the number of knights and the number of fights. Each of the following $*m*$ lines contains three integers $*l*_{*i*}, *r*_{*i*}, *x*_{*i*}$ $(1 ≤ *l*_{*i*} < *r*_{*i*} ≤ *n*; *l*_{*i*} ≤ *x*_{*i*} ≤ *r*_{*i*})$ — the description of the $*i*$-th fight.

翻译中…

It is guaranteed that the input is correct and matches the problem statement. It is guaranteed that at least two knights took part in each battle.

翻译中…

Output

翻译中…

Print $*n*$ integers. If the $*i*$-th knight lost, then the $*i*$-th number should equal the number of the knight that beat the knight number $*i*$. If the $*i*$-th knight is the winner, then the $*i*$-th number must equal $0$.

翻译中…

Note

翻译中…

Consider the first test case. Knights 1 and 2 fought the first fight and knight 1 won. Knights 1 and 3 fought the second fight and knight 3 won. The last fight was between knights 3 and 4, knight 4 won.

翻译中…

样例

Input #1
4 3
1 2 1
1 3 3
1 4 4
Output #1
3 1 4 0
InputCopy OutputCopy
Input #2
8 4
3 5 4
3 7 6
2 8 8
1 8 1
Output #2
0 8 4 6 4 8 6 1
InputCopy OutputCopy
题目信息
题号
356A
时间限制
3 s
内存限制
256 MB
标签
数据结构
并查集

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。