ACM->CF Knight Tournament
来源:互联网 发布:python树莓派编程pdf 编辑:程序博客网 时间:2024/05/16 10:48
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 rihave 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.
Sample Input
4 31 2 11 3 31 4 4
3 1 4 0
8 43 5 43 7 62 8 81 8 1
/*线段树*/ #include <iostream>#include <cstdio>using namespace std;#define MAXN 3 * 100000 + 10struct Node//定义节点 {int l, r, col;};int ans;class SGtree//定义线段树 {Node node[4 * MAXN];public:void Maketree(int i, int l, int r);void Update(int i, int x, int y, int val);void Query(int i, int x);}tree;void SGtree::Maketree(int i, int l, int r){node[i].l = l;node[i].r = r;if (l == r){node[i].col = 0;return ;}int mid = (l + r) >> 1;Maketree(i * 2, l, mid);Maketree(i * 2 + 1, mid + 1, r);}void SGtree::Update(int i, int x, int y, int val){int l = node[i].l;int r = node[i].r;if (l == x && r == y)//更新 {if (!node[i].col){node[i].col = val;}return ;}if (node[i].col)//以前更新过,直接返回 {return ;}int mid = (l + r) >> 1;if (y <= mid){Update(i * 2, x, y, val);}else if (x > mid){Update(i * 2 + 1, x, y, val);}else{Update(i * 2, x, mid, val);Update(i * 2 + 1, mid + 1, y, val);}}void SGtree::Query(int i, int x){int l = node[i].l;int r = node[i].r;if (node[i].col){ans = node[i].col;//查找最早的更新 }if (l == x && r == x){return ;}int mid = (l + r) >> 1;if (x <= mid){Query(i * 2, x);}else{Query(i * 2 + 1, x);}}void input(){int n, m;int x, y, val;scanf("%d %d", &n, &m);tree.Maketree(1, 1, n);//建树 for (int i = 0; i < m; i++){scanf("%d %d %d", &x, &y, &val);if (x == val)//更新,不更新自己 {tree.Update(1, x + 1, y, val);}else if (y == val){tree.Update(1, x, y - 1, val);}else{tree.Update(1, x, val - 1, val);tree.Update(1, val + 1, y, val);}}for (int i = 1; i <= n; i++)//输出 {ans = 0;tree.Query(1, i);printf("%d", ans);printf(" ");}cout << endl;}int main(){input();return 0;}
- ACM->CF Knight Tournament
- Knight Tournament
- Knight Tournament
- CF 356A Knight Tournament(并查集)
- 356A - Knight Tournament
- codeforces356A Knight Tournament
- A. Knight Tournament
- Knight Tournament CodeForces
- codeforces 357C Knight Tournament
- CodeForces 356A Knight Tournament 【线段树】
- CodeForces 357C - Knight Tournament(模拟)
- Codeforces #356C: Knight Tournament 题解
- A. Knight Tournament----并查集
- cf 678E Another Sith Tournament
- ACM->CF
- Codeforces Round #207 (Div. 2) C. Knight Tournament
- codeforce 356 A. Knight Tournament(线段树覆盖,3级)
- CodeForces 356A - Knight Tournament set or 线段树
- SVN:Could not read chunk size 问题的解决。
- C程序设计语言
- 在android中使用main()调试
- 【2013Esri中国用户大会】ArcGIS的大数据挖掘和并行处理
- opencv笔记8----从大恒工业摄像头读取图像
- ACM->CF Knight Tournament
- 使用spring @Scheduled注解执行定时任务
- kill命令
- sql使用指定的值代替查询结果中的值---isnull 、 case···when···then
- 股票做空机构-浑水公司
- 文本文件编码查看 以及转换 enca
- 音视频封装格式、编码格式知识
- firefox插件大全
- .obj 与 .exe 的区别