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.

题解:用set来模拟

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<set> using namespace std;
int a[1000005];
int main()
{
set<int>s;
set<int>::iterator it;
int n,m;
cin>>n>>m;
s.clear();
for(int t=1;t<=n;t++)
{
s.insert(t);
}
int l,r,x;
for (int t=1;t<=m;t++)
{
x=s.size();
scanf("%d%d%d",&l,&r,&x);
it=s.lower_bound(l);
int h;
while (it!=s.end() && *it<=r)
{
h=*it;
it++;
if (h!=x)
{
a[h]=x;
s.erase(h);
}
}
}
printf("%d",a[1]);
for(int t=2;t<=n;t++)
{
printf(" %d",a[t]);
} return 0;
}

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

  1. D - Knight Tournament(set)

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

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

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

  3. 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所 ...

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

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

  5. Knight Tournament 合并区间

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

  6. codeforces 357C Knight Tournament(set)

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

  7. HDU 1372 Knight Moves (bfs)

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

  8. uva439 - Knight Moves(BFS求最短路)

    题意:8*8国际象棋棋盘,求马从起点到终点的最少步数. 编写时犯的错误:1.结构体内没构造.2.bfs函数里返回条件误写成起点.3.主函数里取行标时未注意书中的图. #include<iostr ...

  9. poj2243 Knight Moves(BFS)

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

随机推荐

  1. bzoj 4766: 文艺计算姬 矩阵树定理

    题目: 给定一个一边点数为\(n\),另一边点数为\(m\),共有\(n*m\)条边的带标号完全二分图\(K_{n,m}\) 计算其生成树个数 \(n,m,p \leq 10^{18} ,p为模数\) ...

  2. bzoj 3779: 重组病毒 LCT+线段树+倍增

    题目: 黑客们通过对已有的病毒反编译,将许多不同的病毒重组,并重新编译出了新型的重组病毒.这种病毒的繁殖和变异能力极强.为了阻止这种病毒传播,某安全机构策划了一次实验,来研究这种病毒. 实验在一个封闭 ...

  3. Bootstrap日期/日历插件Datepicker 时间加标记

    由于工作需要,项目中使用了Bootstrap日期/日历插件Datepicker,根据需求需要在其中添加日期标记,实现效果图如下: 特此记录此次解决方案: 1.首先分析了功能的DOM元素(如下图),可以 ...

  4. asp.net异常处理和错误页配置

    最近做一个项目,直接拷贝了前辈写的程序,结果报错了查了半天都没查出原因,也看不出哪里报错,最后发现有一个错误被try...catch了,所以我们做项目的时候一般不需要try...catch. 假设所有 ...

  5. 更改Linux时区的两种方法

    在Azure上的Linux虚拟机启动后默认是UTC的时区.对很多应用要记录时间戳非常的不方便. 本文将介绍两种更改Linux时间戳的方法,供大家参考. 1.修改/etc/localtime文件 控制系 ...

  6. 【转】 Pro Android学习笔记(三八):Fragment(3):基础小例子-续

    目录(?)[-] Step 2实现Fragment指定调用类TitleFragment onInflate和onAttach onCreate和onCreateView onActivityCreat ...

  7. MongoDB优化之二:常见优化方法

    四个方面进行 cpu/io 方面的优化处理: 1.集群架构上进行读写分离.所有查询优先考虑在从库上读取,写操作在主库上执行.避免主库混合读写压力过大,也减少主库上读写记录的锁冲突. connectio ...

  8. ES6学习之数值扩展

    二进制和八进制表示法(二进制用前缀0b(或0B)表示,八进制用前缀0o(或0O)表示) Number('0b111') Number('0o10') Number.isFinite()(判断一个值是否 ...

  9. SpringMVC RESTful中文乱码

    开发中常遇到各种中文乱码很少心烦,这里总结了各种中文乱码https://www.cnblogs.com/lwx521/p/9856186.html 下面以SpringMVC遇到的中文乱码为例详解 首先 ...

  10. linux中历史命令的一点发现

    在LINUX中的终端中输入命令之后,这些命令会被存储到一个文件中,在终端中按下 键盘上的向上的箭头就会显示出以前敲击过的命令,最关键的是重起电脑之后依然有效的,这点和 windows上的CMD有着很大 ...