Codeforces 357C Knight Tournament (set)

Source: Internet
Author: User

Description

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 E Vent.

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

  • There is N Knights participating in the tournament. Each knight is 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 and at most rI had fought for the right T O 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 xm) became the winner of The tournament.

You fished out all the information about the fights from your friends. Now for each knight your want to know the name of the knight he is conquered by. We think that the knight number b is conquered by the knight number aand if there was a fight wit H 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 integers n , m (2≤ n ≤3 10< sup class= "Upper-index" >5; 1≤ m ≤3 105)-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 Sub class= "Lower-index" > i r i )-the description of the i -th fight

It is guaranteed, the input is correct and matches the problem statement. It is guaranteed, at least, Knights took part, 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 th E Knight number I. If the i-th Knight is the winner and then the I-th number must equal 0.

Sample Input

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

Hint

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 is between Knights 3 and 4, Knight 4 won

Test instructions: n individuals to participate in M games, each game gives L,r,x, said the interval "L,r" People are defeated by X, finally asked you everyone is defeated by who, champion output 0.

Analysis: Throw all the N people into set, according to the given [L,r],x, do it well.

1 /*************************************************************************2 > File name:365a.cpp3 > Author:4 > Mail:5 > Created time:2016 July 29 Friday 20:54 32 seconds6  ************************************************************************/7 8#include <iostream>9#include <bits/stdc++.h>Ten using namespacestd; One Const intMAXN = 3e5+7; A Set<int>St; - Set<int>:: iterator IT,ITE,CNT[MAXN]; - intANS[MAXN]; the  - intMain () - { -     intn,m; +CIN >> N >>m; -memset (ans,0,sizeof(ans)); +      for(inti =1; i<= N; i++) A     { at St.insert (i); -     } -     intl,r,x; -      while(m--) -     { -CIN >> L >> R >>x; inITE =St.lower_bound (l); -         intnum =0; to          for(it = ite; *it <= r && It! = St.end (); it++) +         { -             if(*it! =x) the             { *Ans[*it] =x; $cnt[num++] =it;Panax Notoginseng             } -         } the          for(inti =0; i< num; i++) +         { A st.erase (Cnt[i]); the         } +     } -cout << ans[1]; $      for(inti =2; i<= n;i++) $     { -cout <<' '<<Ans[i]; -     } thecout <<Endl; -     return 0;Wuyi}

Codeforces 357C Knight Tournament (set)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.