Knight Tournament (set)
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 ≤ n; li ≤ 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)的更多相关文章
- D - Knight Tournament(set)
Problem description Hooray! Berl II, the king of Berland is making a knight tournament. The king has ...
- CodeForce 356A Knight Tournament(set应用)
Knight Tournament time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- 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所 ...
- CodeForces - 357C Knight Tournament 伪并查集(区间合并)
Knight Tournament Hooray! Berl II, the king of Berland is making a knight tournament. The king has a ...
- Knight Tournament 合并区间
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the me ...
- codeforces 357C Knight Tournament(set)
Description Hooray! Berl II, the king of Berland is making a knight tournament. The king has already ...
- HDU 1372 Knight Moves (bfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1372 Knight Moves Time Limit: 2000/1000 MS (Java/Othe ...
- uva439 - Knight Moves(BFS求最短路)
题意:8*8国际象棋棋盘,求马从起点到终点的最少步数. 编写时犯的错误:1.结构体内没构造.2.bfs函数里返回条件误写成起点.3.主函数里取行标时未注意书中的图. #include<iostr ...
- poj2243 Knight Moves(BFS)
题目链接 http://poj.org/problem?id=2243 题意 输入8*8国际象棋棋盘上的两颗棋子(a~h表示列,1~8表示行),求马从一颗棋子跳到另一颗棋子需要的最短路径. 思路 使用 ...
随机推荐
- python【事物 】【数据库锁】
1.数据库事物 1. 什么是事务 事务是应用程序中一系列严密的操作,所有操作必须成功完成,否则在每个操作中所作的所有更改都会被撤消.也就是事务具有原子性,一个事务中的一系列的操作要么全部成功,要么一 ...
- Swift中的参数内部名称和外部名称
1.什么是参数的内部名称和外部名称? struct Color { let red, green, blue: Double init(red redColor: Double,green green ...
- 标准模板库(STL)学习指南之priority_queue优先队列
转载自CSDN博客:http://blog.csdn.net/suwei19870312/article/details/5294016 priority_queue 调用 STL里面的 make_h ...
- 【转】 Pro Android学习笔记(四七):Dialog(4):一些补充和思考
目录(?)[-] 编程思想封装接口 fragment和activity以其他fragment之间的通信 编程思想:封装接口 在小例子中,fragment会调用activity的onDialogDone ...
- Java中是构造器创建对象吗?
首先,这里说明” Java中是构造器创建对象 “这句话是完全错误的. Java中构造器的作用主要是为了初始化变量的值...其实在执行构造器之前,Java对象所需要的内存空间,已经产生了... 一般可以 ...
- Android Studio的Android Monitor窗口中把标签拉出来之后放不回去的解决方法
不小心把下图方框中的logcat标签拖出来之后, 就变成了图2的浮动窗口,发现logcat标签怎么也弄不回原来窗口中的位置中. 其实解决方法很简单,只要拖住下图浮动窗口中红框位置的logcat标签,然 ...
- tomcat 自带jdk
http://blog.csdn.net/b452608/article/details/70143466
- python 基础 序列化
转自https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/00138683221577 ...
- excel2003, 2007最大行列、sheet数
1.excel2003版本一个工作表最多可有65536行,行用数字1—65536表示; 256列,列用英文字母A—Z,AA—AZ,BA—BZ,……,IA—IV表示.2.一个工作簿中最多含有25 ...
- Learning Python 004 基础的数据类型和变量
Python 基础的数据类型和变量 数据类型 整数 Python可以处理任意大小的整数,当然包括负整数. Python表示十六进制也用0x前缀. 浮点数 1.23x10^9和12.3x10^8是完全相 ...