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 n, m (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.

Example

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.

难怪总是超时,没判断完一个元素应该让他等于区间尾部的元素的下一个元素的编号才对

而不是等于尾部元素

代码:

#include <iostream>
#include <cstdio>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
int main()
{
int a[]={},b[],n,m,x,y,z,temp;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
b[i]=i+;
for(int k=;k<m;k++)
{
scanf("%d%d%d",&x,&y,&z);
if(x>y)swap(x,y);
for(int i=x;i<z;i=temp)
{
temp=b[i];
if(!a[i])a[i]=z;
b[i]=z;
}
for(int i=z+;i<=y;i=temp)
{
temp=b[i];
if(!a[i])a[i]=z;
b[i]=b[y];///注意这一步 应该等于y得下一个 而不是等于y
}
}
for(int i=;i<=n;i++)
printf("%d ",a[i]);
}

Knight Tournament 合并区间的更多相关文章

  1. CodeForces - 357C Knight Tournament 伪并查集(区间合并)

    Knight Tournament Hooray! Berl II, the king of Berland is making a knight tournament. The king has a ...

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

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

  3. D - Knight Tournament(set)

    Problem description Hooray! Berl II, the king of Berland is making a knight tournament. The king has ...

  4. codeforces 357C Knight Tournament(set)

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

  5. [LeetCode] Merge Intervals 合并区间

    Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8, ...

  6. lintcode:合并区间

    题目: 合并区间 给出若干闭合区间,合并所有重叠的部分. 样例 给出的区间列表 => 合并后的区间列表: [ [ [1, 3], [1, 6], [2, 6], => [8, 10], [ ...

  7. LeetCode(56):合并区间

    Medium! 题目描述: 给出一个区间的集合,请合并所有重叠的区间. 示例 1: 输入: [[1,3],[2,6],[8,10],[15,18]] 输出: [[1,6],[8,10],[15,18] ...

  8. HRBUST - 1818 石子合并 区间dp入门

    有点理解了进阶指南上说的”阶段,状态和决策“ /* 区间dp的基础题: 以区间长度[2,n]为阶段,枚举该长度的区间,状态dp[l][r]表示合并区间[l,r]的最小费用 状态转移方程dp[l][r] ...

  9. 【LeetCode】数组--合并区间(56)

    写在前面   老粉丝可能知道现阶段的LeetCode刷题将按照某一个特定的专题进行,之前的[贪心算法]已经结束,虽然只有三个题却包含了简单,中等,困难这三个维度,今天介绍的是第二个专题[数组] 数组( ...

随机推荐

  1. nginx反向代理和正向代理,优缺点

    http://blog.csdn.net/lishaojun0115/article/details/53200629 nginx反向代理代理的是服务器,正向代理代理的是客户端, 反向代理是客户点发送 ...

  2. 慕课网Hibernate初探之一对多映射实验及总结

    慕课网Hibernate初探之一对多映射实验及总结 一.本课核心 * 1.如何在MyEclipse中使用Hibernate * 2.如何实现Hibernate中一对多的映射 * 3.如何创建Sessi ...

  3. API网关 动态路由、监控、授权、安全、调度

    1.API网关介绍 API网关是一个服务器,是系统的唯一入口.从面向对象设计的角度看,它与外观模式类似.API网关封装了系统内部架构,为每个客户端提供一个定制的API.它可能还具有其它职责,如身份验证 ...

  4. win7创建 VirtualBox COM 对象失败。 应用程序现在将终止。 Callee RC: E_NOINTERFACE (0x80004002)

    win7创建 VirtualBox COM 对象失败.  应用程序现在将终止.    Callee RC: E_NOINTERFACE (0x80004002) 启动VirtualBox提示这个错误, ...

  5. 如何给wpf的按钮添加背景图片

    1:简单实用 <Button Height="143" HorizontalAlignment="Left" Margin="30,34,0,0 ...

  6. H5基础知识(一)

    一.概述 HTML5  是html4.0 升级版 结构 Html5 .样式 css3 .行为: API  都有所增强 HTML5并不仅仅只是做为HTML标记语言的一个最新版本,更重要的是它制定了Web ...

  7. laravel时间判断

    $now = Carbon::now(); if ($now >= '2019-01-02') { }

  8. 『cs231n』作业3问题1选讲_通过代码理解RNN&图像标注训练

    一份不错的作业3资料(含答案) RNN神经元理解 单个RNN神经元行为 括号中表示的是维度 向前传播 def rnn_step_forward(x, prev_h, Wx, Wh, b): " ...

  9. 常见MIME类型例表

    常见MIME类型例表: 序号 内容类型 文件扩展名 描述 1 application/msword doc Microsoft Word 2 application/octet-stream bin ...

  10. $digest already in progress 解决办法

    Solution In short, instead of doing this: ... your controller code... $http.get('some/url', function ...