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表示行),求马从一颗棋子跳到另一颗棋子需要的最短路径. 思路 使用 ...
随机推荐
- SPOJ8093Sevenk Love Oimaster(广义后缀自动机)
Oimaster and sevenk love each other. But recently,sevenk heard that a girl named ChuYuXun was da ...
- 洛谷P2878 [USACO07JAN]保护花朵Protecting the Flowers
题目描述 Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. ...
- js---数组习题---
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- docker出现错误 could not read CA certificate
1. 问题描述 $ docker login # 无法正常使用 其他一堆命令,显示验证失败之类的问题 2. 解决方案 $ unset DOCKER_TLS_VERIFY $ unset DOCKER_ ...
- js拼的onclick调用方法需要注意的地方 之一
1.首先,明确一点,js方法中参数可以传递字符串,对象,number类型等,对象传递的是引用,方法中修改了,会影响到方法外面的对象. 2.下面重现项目中遇到的一个问题:(其实就是要明白通过引号来拼接字 ...
- java.util.Date、java.sql.Date、java.sql.Time、java.sql.Timestamp区别和联系
java.util.Date.java.sql.Date.java.sql.Time.java.sql.Timestamp区别和联系 栏目:Java基础 作者:admin 日期:2015-04-19 ...
- XML解析,出现ClassCastException 原因
import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.Docum ...
- [51nod1101]换零钱
题意:给定钱,计算其能换成零钱的分类种数. 解题关键:完全背包计数. $dp[i][j]$表示前i个物品构成j元的种类数,然后优化一维. #include<bits/stdc++.h> u ...
- JS设置cookie、读取cookie、删除cookie(转)
JS设置cookie.读取cookie.删除cookie 转载 2015-04-17 投稿:hebedich 我要评论 Js操作Cookie总结(设置,读取,删除),工作中经常会用到的哦! ...
- mongodb的备份还原
一:备份数据库 G:\Program Files\MongoDB\Server\3.0\bin>mongodump -d mydb -o g:/data/back mongodump -h IP ...