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. VHDL之concurrent之block

    1 Simple BLOCK The simple block represents only a way of partitioning the code. It allows concurrent ...

  2. 【sqli-labs】 less24 POST- Second Order Injections *Real treat* -Stored Injections (POST型二阶注入 *真的好玩?* 存储注入)

    简单登陆浏览一遍后,发现是一个登陆注册修改密码的应用 审查一下代码 登陆页面的username,password使用了转义 注册页面的参数也进行了转义处理 但是在修改password的页面,直接从se ...

  3. vue2.0模拟锚点实现定位平滑滚动

    vue2.0模拟锚点实现定位平滑滚动 效果为点击哪一个标题,平滑滚动到具体的详情. 如果是传统项目,这个效果就非常简单.但是放到 Vue 中,就有两大难题: 1. 在没有 jQuery 的 anima ...

  4. react构建前端项目方法汇总

    react简介: 一.使用react 创建一个PC端的项目 (a):使用 yemon 创建一个 webpack 的 react 的项目 控制台安装并且产看 yemon 的版本 yo -v (b): 全 ...

  5. marquee标签弹幕效果

    播放个视频的时候看到很有趣的弹幕,想着前端能不能做个弹幕效果.弹幕是滚动的,所以首先想到了<marquee>标签.但事实上,<marquee>标签不是w3c的标准,只是主流的浏 ...

  6. Apex语言(七)集合

    1.集合 集合是可以存储多个记录数的变量类型. List列表集合可以包含任何数量的数据,与数组类似. Set列表集合包含多个无序的唯一记录数,集合不能具有重复记录,与列表类似. Map地图是一个键值对 ...

  7. Webpack 快速上手(下)

    杏仁前端开发工程师,代码洁癖症早期,关注前端技术. 由于文章篇幅较长,为了更好的阅读体验,本文分为上.中.下三篇: 上篇介绍了什么是 webpack,为什么需要 webpack,webpack 的文件 ...

  8. bzoj 4994: [Usaco2017 Feb]Why Did the Cow Cross the Road III 树状数组_排序

    Description 给定长度为2N的序列,1~N各处现过2次,i第一次出现位置记为ai,第二次记为bi,求满足ai<aj<bi<bj的对数 题解: 方法一: 搞一个KDtree, ...

  9. 【转载】Java 反射详解

    目录 1.什么是反射? 2.反射能做什么? 3.反射的具体实现 4.根据反射获取父类属性 4.反射总结 反射反射,程序员的快乐! 1.什么是反射? Java反射就是在运行状态中,对于任意一个类,都能够 ...

  10. Innodb 中的事务隔离级别和锁的关系

    转自:https://tech.meituan.com/innodb-lock.html 前言: 我们都知道事务的几种性质,数据库为了维护这些性质,尤其是一致性和隔离性,一般使用加锁这种方式.同时数据 ...