Knight Tournament (SET的使用)

逆向工程视角:MFI芯片通信协议在Linux环境下的行为分析 本文从逆向工程角度深入分析了MFI芯片在Linux环境下的通信协议行为,重点探讨了树莓派与MFI芯片通过I2C接口交互的技术细节。文章详细介绍了信号捕获、协议栈逆向、动态调试技巧以及安全机制分析,为开发者提供了在Linux驱动层面实现MFI认证的实用方法。 阅读详情

Knight Tournament

 

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.

Examples
Input
4 3
1 2 1
1 3 3
1 4 4
Output
3 1 4 0 
Input
8 4
3 5 4
3 7 6
2 8 8
1 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.

大意:先输入n,m,表示比赛的成员和比赛的次数。接下来m场比赛,依次输入l,r,x。比赛成员范围从l到r,如果该成员未被淘汰,则被x打败(自己不能打败自己)。输出1-n中该成员被谁打败,如果没被打败过,输出0


思路:如果简单暴力的话就会超时。使用SET标记,被打败过的成员便移除set。


AC代码:

#include <cstdio>   
#include <iostream> 
#include <algorithm> 
#include <cmath> 
#include <cstdlib> 
#include <cstring> 
#include <vector> 
#include <list> 
#include <map> 
#include <stack> 
#include <queue> 
#include <set>
using namespace std; 
#define ll long long 
int a[333333];
int main() 
{ 
	int n,m;
	while(cin >> n >> m)
	{
		set<int> s;
		for(int i = 1;i <= n;i++)
			s.insert(i);
		memset(a,0,sizeof(a));
		for(int i = 0;i < m;i++)
		{
			int temp[333333];
			int sum = 0;
			int l,r,x;
			scanf("%d%d%d",&l,&r,&x);
			set<int>::iterator it = s.lower_bound(l);
			while(it != s.end()&&*it <= r)
			{
				if(*it != x&&!a[*it])
				{
					a[*it] = x;
					temp[sum++] = *it;
				}
				it++;
			}
			for(int j = 0;j < sum;j++)
				s.erase(temp[j]);
		}
		for(int i = 1;i < n;i++)
			printf("%d ",a[i]);
		printf("%d\n",a[n] );
	}
    //cout << "AC" <<endl; 
    return 0; 
} 

Ubuntu 22.04 局域网安装GitLab 下面直接给你一份。 阅读详情

相关推荐

Labview调用C++ dll之字符串数组传递

做项目的时候碰到了一个需求,有一个复杂的运算,用labview实现非常的麻烦,但是如果用C++实现,就会灵活很多。尝试着采用Labview调用C++编写的动态链接库方式解决,兼顾Labview的便利和C++的灵活性。 运算好说,主要难点是Labview与C++之间的数据对应关系,因为我最后的结果是既有字符串又有数字,对于单纯的数字来说,直接通过调用数组的方式就能解决,这里主要记录一下字符串数组...

bgbgx的博客 6809

Knight Tournament(路径压缩-易懂)

Knight Tournament: Knight Tournament 原题: Knight Tournament time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Hooray! Berl II, the king of Berlan...

四年rain的博客 321

PLC作为Modbus TCP客户端

PLC作为Modbus TCP客户端,Modbus Slave作为服务器

soledad_chao的博客 4378

Knight Tournament

set的应用 一个人只能被打败一次,所以在被打败后就要从set中删去,这样才能保证从左边界遍历到右边界的过程中消耗较少的时间,如果纯暴力不优化的话肯定会超时 Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all kn

smoggyxhdz的博客 413

x86架构学习之中断

外部中断,一般是由CPU的外部引脚电信号触发,这些引脚留给硬件厂商去定义中断,例如主板厂商可以将USB中断挂载70号中断引脚上,MCU厂商可以将片上外设(SPI、I2C等)的中断挂载在指定中断线上。中断描述符主要用于说明该中断的入口地址,中断描述符表则是将中断描述符一项一项管理在一个数组中,每一项中断描述符占用8个字节(64位模式下,占用16字节),其。简称中断,后文如果没特别说明,中断都指外部中断,由外部IO事件触发,由于时钟源来自CPU外部,与CPU时钟不同源,因此是异步事件。

qq_26962739的博客 1571

GEE生物量预测:利用多源遥感数据和随机森林算法RF构建地上生物量(AGB)预测模型,并实现未来年份的生态变化模拟(大面积生物量反演)

数据融合策略:整合5类遥感产品(AGB、NDVI、LAI、土地覆盖、地形)时序特征构建:采用生长季中值法降低云污染影响机器学习优化分层采样保证数据代表性80棵决策树平衡精度与效率预测可靠性基准期R²达0.76需结合地面实测数据校正。

此星光明博客 419

356A.Knight Tournament(区间处理)

356A.Knight Tournament time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Hooray! Berl II, the king of Berland is making a knight tournament. The...

qq_43816599的博客 244

[Python] 如何使用 Python 调用 Dify 工作流服务实现自动化翻译

本文介绍了如何使用Python调用Dify的API实现文本翻译自动化。Dify作为AI开发平台,其工作流功能可执行文本处理、翻译等任务。选择Python调用Dify的优势在于职责划分清晰:Dify专注AI服务,Python处理文件操作等非AI任务。

技术小甜甜:传播可落地技术,帮助个人和企业降低解决真实场景问题的成本 1096

CodeForces 356A_(set应用,线段树)

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

weixin_34268169的博客 218

【Python】-- 趣味代码 - 发牌游戏

Python -- 趣味代码 - 发牌游戏

银尘博客 351

AUTOSAR知识点:PDUR(PDU Router)基础知识

通过定义路由表和实现相应的路由和缓冲逻辑,PDUR能够确保PDU在不同ECU之间的可靠传输。在上述示例中,我们定义了一个简单的PDUR路由表,其中列出了源ECU和目标ECU之间的映射关系。当收到来自源ECU的PDU时,PDUR模块会根据路由表查找目标ECU,并将PDU传输到相应的目标ECU。PDUR的主要功能是将接收到的PDU从一个ECU路由到另一个ECU,并确保数据的正确传输。需要注意的是,上述示例是一个简化的实现,实际的PDUR模块可能包含更复杂的功能和逻辑。

EcmFsharp的博客 1157

【线段树||set遍历】Codeforces Round #207 (Div. 1) A. Knight Tournament

Codeforces Round #207 (Div. 1) A. Knight Tournament 题意: n个骑士(编号1-n),有m场battle,保证每一场battle的人数>=2。给出m场battle的信息:每一场battle的信息是:给出一个区间[l, r],再给出一个该场battle的胜利者编号won,意思就是说[l, r]中还没有被打败的骑士都会在这一场被won打...

L_X_ 301

71、CAN总线双绞线绞距与抗共模干扰的定量关系

摘要:本文探讨了CAN总线双绞线绞距与抗共模干扰的定量关系。通过理论推导得出共模电压与绞距平方成正比,绞距越小抑制效果越好。工程实践表明,工业现场推荐绞距不超过30mm,高频干扰场景需优先优化绞距。实测数据验证了绞距均匀性的重要性,建议控制在15-25mm范围,安装时保持绞合结构完整。案例显示,将绞距从50mm改为15mm后,共模干扰从12V降至1.8V,有效解决了CAN通信问题。绞距选择需兼顾理论计算与现场实测,同时注意与屏蔽层的协同设计。

2401_88858637的博客 186

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

black_hole6的博客 327

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

A. Knight Tournament SET的应用

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

weixin_30239339的博客 126

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

CodeForces 356A - Knight Tournament set or 线段树

题意:                          现在有N个骑士进行M轮PK...现在告诉这M轮是谁站在台上...其将l~r所存在的骑士都打败..而若一个骑士被打败..就出局了..也就是不存在了...请输出每个骑士是被哪个骑士打败的(最后的胜利者输出0)...保证有解..                题解:                            比赛的时候就是没看懂

zzyzzy12 1782

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

D - Knight Tournament(set)

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

weixin_30470857的博客 87

CodeForce 356A Knight Tournament(set应用)

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 m

LYHVOYAGE的专栏 1812

CodeForces - 357C Knight Tournament (set乱搞/并查集)

题目链接http://codeforces.com/problemset/problem/357/C点击打开链接 C. Knight Tournament time limit per test 3 seconds memory limit per test 256 megabytes input standard input

xuejye的博客 353

基于Flask与SQLite构建轻量级自定义问答系统实战

问答系统作为人机交互的核心组件,其基本原理是通过前端界面接收用户输入,后端逻辑处理并存储数据,最终将结果反馈给用户。在Web开发领域,采用Python的Flask框架结合SQLite数据库,是实现轻量级、高度自定义系统的经典技术方案。这种架构的价值在于其快速开发、易于部署和维护的特点,尤其适合个人项目、创意互动或小型社区场景。例如,在二次元同人创作或角色设定(私设)中,开发者常需要为原创角色构建专属的互动平台,这正是Flask和SQLite的典型应用。本文将以一个名为“超中二私设德家ask”的问答系统为例,

weixin_33937499的博客 433

CodeForces - 357C C - Knight Tournament 并查集or 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

Marcus-Bao的个人主页 1165

CodeForces - 356A Knight Tournament(线段树,或并查集,或set)

题目链接 题目大意 一些骑士打架,输了就淘汰,输出一个数组,表示第i个人是被a[i]淘汰的。 因为涉及到区间的修改,不可避免的想到了线段树,可惜菜鸡只会用区间加的板子,这种值替换的线段树不会写,菜哭了。 还是一手正难则反,考虑倒着处理每一次战斗,这样可以覆盖之前的的修改。 代码 #include<iostream> #include<cstdio> using namesp...

Novice_的博客 271

Codeforces Round #207 (Div. 2)C. Knight Tournament(SET也可以搞定)

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

布生气 1506

Codeforces Round #207 (Div. 2) C. Knight Tournament (STL中的set处理)

http://codeforces.com/contest/357/problem/C 题意: 第一行输入n,m,n表示有n个人(标号1~n),m表示有m 场战斗,接下来m行,每行输入l , r , x  ,表示标号从l 到 r的人进行了一场战斗,其中x (l Sample test(s) input 4 3 1 2 1 1 3 3 1 4 4 out

cowboy90的专栏 760
上一篇: 线性素数筛选法模板
下一篇: 博弈论(巴什博奕,威佐夫博弈,尼姆博弈,斐波那契博弈)
MMMMMMMW
博客等级 码龄9年 34粉丝 64原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值