Problem 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 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 li and at most ri 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 xi, 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 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 nm (2 ≤ n ≤ 3·105; 1 ≤ m ≤ 3·105) — the number of knights and the number of fights. Each of the following m lines contains three integers li, ri, xi (1 ≤ li < ri ≤ nli ≤ xi ≤ ri) — 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.

Examples

Input

4 3
1 2 1
1 3 3
1 4 4

Output

3 1 4 0 

Input

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

Output

0 8 4 6 4 8 6 1 

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.

解题思路:题目的意思就是给出n(表示n个骑士,编号为1~n)和m(m行比赛数据),其中l,r,x表示[l,r]中除x编号外都被x打败,最后第m行数据的x是最终的胜利者,其"被打败的编号"为0,要求输出每个骑士(1~n)被打败的骑士编号。注:输入数据已经保证每个骑士都参加战斗。显然题目给的数据范围很大,两重循环就TLE。怎么优化呢?做法:将编号1~n仍在set容器中,采用lower_bound()找到容器中l元素(迭代器)的位置,然后在区间[l,r]中除x外将被打败的骑士编号标记起来(即s[i]=x,s数组中元素初始值要全部清0),再删除容器中已被打败的骑士编号,最后输出每个骑士被打败的骑士编号即可。

AC代码(1871ms):

 #include<bits/stdc++.h>
using namespace std;
const int maxn = 3e5+;
int n,m,l,r,x,cnt,s[maxn];
set<int> st;
set<int>::iterator it,its,tmp[maxn];
int main(){
cin>>n>>m;
for(int i=;i<=n;++i)st.insert(i);//将编号1~n全都扔到set容器中
memset(s,,sizeof(s));//s数组存放下标i被编号x打败,初始值注意清0
while(m--){
cin>>l>>r>>x;cnt=;
its=st.lower_bound(l);//找到不小于l的迭代器的位置
for(it=its;it!=st.end()&&(*it<=r);++it)//[l,r]区间中除x外都已被x打败
if(*it!=x){s[*it]=x;tmp[cnt++]=it;}
for(int i=;i<cnt;++i)//删除已被打败的编号
st.erase(tmp[i]);
}
for(int i=;i<=n;++i)
cout<<s[i]<<(i==n?"\n":" ");
return ;
}

D - Knight Tournament(set)的更多相关文章

  1. CodeForce 356A Knight Tournament(set应用)

     Knight Tournament time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  2. HDU 1372 Knight Moves (bfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1372 Knight Moves Time Limit: 2000/1000 MS (Java/Othe ...

  3. Knight Tournament (set)

    Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the me ...

  4. Codeforces Round #207 (Div. 1) A. Knight Tournament (线段树离线)

    题目:http://codeforces.com/problemset/problem/356/A 题意:首先给你n,m,代表有n个人还有m次描述,下面m行,每行l,r,x,代表l到r这个区间都被x所 ...

  5. poj2243 Knight Moves(BFS)

    题目链接 http://poj.org/problem?id=2243 题意 输入8*8国际象棋棋盘上的两颗棋子(a~h表示列,1~8表示行),求马从一颗棋子跳到另一颗棋子需要的最短路径. 思路 使用 ...

  6. ZOJ 1091 (HDU 1372) Knight Moves(BFS)

    Knight Moves Time Limit: 2 Seconds      Memory Limit: 65536 KB A friend of you is doing research on ...

  7. HDU1372 Knight Moves(BFS) 2016-07-24 14:50 69人阅读 评论(0) 收藏

    Knight Moves Problem Description A friend of you is doing research on the Traveling Knight Problem ( ...

  8. 【UVa】439 Knight Moves(dfs)

    题目 题目     分析 没有估价函数的IDA......     代码 #include <cstdio> #include <cstring> #include <a ...

  9. 山东省第七届省赛 D题:Swiss-system tournament(归并排序)

    Description A Swiss-system tournament is a tournament which uses a non-elimination format. The first ...

随机推荐

  1. (转)PostGIS+QGIS+GeoServer+OpenLayers实现数据的存储、服务的发布以及地图的显示

    http://blog.csdn.net/gisshixisheng/article/details/41575833 标题比较长,主要呢是实现以下几点: 1.将shp数据导入到PostGIS中: 2 ...

  2. js俄罗斯方块

    <html> <style>.c {margin :1px;width:19px;height:19px;background:red;position:absolute;} ...

  3. PAT_A1122#Hamiltonian Cycle

    Source: PAT A1122 Hamiltonian Cycle (25 分) Description: The "Hamilton cycle problem" is to ...

  4. 【编程工具】Vim编辑器的使用

    1.Vim简介   Vim最初起源于古老的贝尔实验室,由"Bram Moolenaar等人"开发,是一个功能强大的文本编辑器,被推崇为类Vi编辑器中最好的一个.   Vim是一个类 ...

  5. 7.5 pragma 指令

    第1个pragma禁用了我们感兴趣的特别警告,第2个恢复了它.禁用尽可能小的一段代码的警告是一个良好的做法,以便你不会错过任何真正应该修复的错误.如果你想在单独一行上禁用或恢复多个警告,那么只需用逗号 ...

  6. 操作符重载、继承(day08)

    二十 操作符重载 函数操作符"()" 功能:让对象当做函数来使用 注:对参数的个数.返回类型没有限制 eg: class A{...}; A a; //a.operator()(1 ...

  7. 企业版 Linux 附加软件包(EPEL)

    企业版 Linux 附加软件包(以下简称 EPEL)是一个由特别兴趣小组创建.维护并管理的,针对 红帽企业版 Linux(RHEL)及其衍生发行版(比如 CentOS.Scientific Linux ...

  8. oracle 单独开始一个事物的写法 。

    SET TRANSACTION NAME 'Update salaries'; SAVEPOINT before_salary_update; UPDATE employees SET salary= ...

  9. java构造函数重载this(true)

    看storm的代码的时候,发现这样一句java代码, 很是不理解 google之后,发现原来是java语法中,构造函数重载,this()调用的其实就是 构造函数.This is constructor ...

  10. 进行mysql压力測试须要注意的几点

    1.填充測试数据比物理内存还要大,至少超过innodb_buffer_pool_size 值,不能将数据所有装载到内存中,除非你的本意就想測试全内存状态下的MySQL性能. 2.每轮測试完毕后,都重新 ...