博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforce 356 A. Knight Tournament(线段树覆盖,3级)
阅读量:4313 次
发布时间:2019-06-06

本文共 3874 字,大约阅读时间需要 12 分钟。

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

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

Sample test(s)
input
4 31 2 11 3 31 4 4
output
3 1 4 0
input
8 43 5 43 7 62 8 81 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.

思路:1.直接线段树覆盖,从后往前

           2.从前往后,用set 查找区间,然后标记,删除。

#include
#include
#include
#include
#include
#include
#define FOR(i,a,b) for(int i=a;i<=b;++i)#define clr(f,z) memset(f,z,sizeof(f))#define lson t<<1#define rson t<<1|1using namespace std;const int mm=6e5+9;int ans[mm];class Node{ public:int l,r,who,lazy;}rt[mm*4];int max_node;void build(int t,int l,int r){ max_node=max(max_node,t); rt[t].l=l;rt[t].r=r; rt[t].lazy=-1;rt[t].who=0; if(l==r)return; int mid=(l+r)/2; build(lson,l,mid);build(rson,mid+1,r);}class ppp{ public:int l,r,x,len; bool operator<(const ppp&t)const { if(len^t.len)return len
=rt[lson].l)update(lson,l,r,x); if(r>=rt[rson].l&&l<=rt[rson].r)update(rson,l,r,x); rt[t].lazy=-1;}int query(int t,int x){ if(rt[t].lazy>=0)return rt[t].lazy; if(rt[t].l==x&&rt[t].r==x) { return rt[t].who; } if(rt[lson].r>=x)return query(lson,x); else return query(rson,x);}int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { max_node=0; build(1,1,n); FOR(i,1,m) {scanf("%d%d%d",&f[i].l,&f[i].r,&f[i].x);f[i].len=f[i].r-f[i].l; } int pos=m; for(int i=m;i>=1;--i) { if(f[i].x==f[i].l) { f[i].l++; } else if(f[i].x==f[i].r) --f[i].r; else if(f[i].x>f[i].l&&f[i].x

转载于:https://www.cnblogs.com/nealgavin/p/3797496.html

你可能感兴趣的文章
python-----python的文件操作
查看>>
java Graphics2d消除锯齿,使字体平滑显示
查看>>
控件中添加的成员变量value和control的区别
查看>>
Spring Boot Docker 实战
查看>>
Div Vertical Menu ver3
查看>>
Git简明操作
查看>>
InnoDB为什么要使用auto_Increment
查看>>
课堂练习之买书打折最便宜
查看>>
定义函数
查看>>
网络虚拟化技术(二): TUN/TAP MACVLAN MACVTAP
查看>>
MQTT协议笔记之mqtt.io项目HTTP协议支持
查看>>
(转)jQuery中append(),prepend()与after(),before()的区别
查看>>
Tecplot: Legend和图像中 Dashed/Dash dot/Long dash 等虚线显示没有区别的问题
查看>>
win8 开发之旅(2) --连连看游戏开发 项目错误的总结
查看>>
视频转换工具ffmpeg
查看>>
一、 object c -基础学习第一天 如何定义一个类
查看>>
C#调用C++编译的DLL详解
查看>>
Kali Linux的安装
查看>>
我的大学生活-5-08-赵心宁
查看>>
SQLServer视图
查看>>