#线段树,倒序#CF356A Knight Tournament
分析
要求覆盖必须是第一个覆盖的,
考虑最后一个覆盖的很简单做线段树区间赋值,
那么倒序区间赋值就可以了
代码
#include <cstdio>
#include <cctype>
#define rr register
using namespace std;
const int N=300011;
struct rec{int l,r,x;}q[N];
int w[N<<2],n,m;
inline signed iut(){
rr int ans=0; rr char c=getchar();
while (!isdigit(c)) c=getchar();
while (isdigit(c)) ans=(ans<<3)+(ans<<1)+(c^48),c=getchar();
return ans;
}
inline void print(int ans){
if (ans>9) print(ans/10);
putchar(ans%10+48);
}
inline void update(int k,int l,int r,int x,int y,int z){
if (l==x&&r==y) {w[k]=z; return;}
rr int mid=(l+r)>>1;
if (w[k]) w[k<<1]=w[k<<1|1]=w[k],w[k]=0;
if (y<=mid) update(k<<1,l,mid,x,y,z);
else if (x>mid) update(k<<1|1,mid+1,r,x,y,z);
else update(k<<1,l,mid,x,mid,z),update(k<<1|1,mid+1,r,mid+1,y,z);
}
inline void query(int k,int l,int r){
if (l==r) {print(w[k]),putchar(32); return;}
rr int mid=(l+r)>>1;
if (w[k]) w[k<<1]=w[k<<1|1]=w[k],w[k]=0;
query(k<<1,l,mid);
query(k<<1|1,mid+1,r);
}
signed main(){
n=iut(); m=iut();
for (rr int i=1;i<=m;++i) q[i]=(rec){iut(),iut(),iut()};
for (rr int i=m;i;--i){
if (q[i].l<q[i].x) update(1,1,n,q[i].l,q[i].x-1,q[i].x);
if (q[i].x<q[i].r) update(1,1,n,q[i].x+1,q[i].r,q[i].x);
}
query(1,1,n);
return 0;
}
#线段树,倒序#CF356A Knight Tournament的更多相关文章
- POJ 2828 Buy Tickets 线段树 倒序插入 节点空位预留(思路巧妙)
Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 19725 Accepted: 9756 Desc ...
- 【题解】CF356A Knight Tournament
题面传送门 本蒟蒻想练习一下并查集,所以是找并查集标签来这里的.写题解加深理解. 解决思路 自然,看到区间修改之类很容易想到线段树,但本蒟蒻线段树会写挂,所以这里就讲比较简单的并查集思路. 并查集的核 ...
- 线段树(倒序操作):POJ 2828 Buy Tickets
Buy Tickets Description Railway tickets were difficult to buy around the Lunar New Year in China, ...
- 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所 ...
- hdu5592 倒序求排列+权值线段树
这种题为什么要用到主席树啊..8说了,直接上代码 /* 1-n的排列,给定所有前缀的逆序对数量,要求恢复排列 首先能确定最后一个数是什么,然后倒序确定即可 开线段树找空位:如果Ai-Ai-1=k,说明 ...
- poj2528 线段树+离散化 (倒序)
The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign h ...
- CodeForce 356A Knight Tournament(set应用)
Knight Tournament time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- CodeForces 356A_(set应用,线段树)
A. Knight Tournament time limit per test 3 seconds memory limit per test 256 megabytes input standar ...
- 【POJ2828】Buy Tickets(线段树)
题意:有一个输入序列,每次操作要把b[i]插入到第a[i]个,在第a[i]个后面的要后移,问最后序列. n<=200000 思路:顺序来只能用splay维护 考虑倒序,对于插入到第K个位置,在线 ...
- HDU 4902 Nice boat (线段树)
Nice boat 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4902 Description There is an old country a ...
随机推荐
- 具备有效期的sessionStorage存储
具备有效期的sessionStorage存储 类方式 // 具备有效期的sessionStorage存储-类方式. class SessionStorageWrapper { // 存储数据到sess ...
- mysql中如何批量生成百万级数据
# 准备 #1. 准备表 create table s1( id int, name varchar(20), gender char(6), email varchar(50), first_nam ...
- 运行python的几种方式
1. 通过cmd终端去运行 按住win + r 打开命令提示符,然后输入python,就可以进入python环境,输入你需要指定的python代码即可. # 注意:这种方法只是建议临时使用一下,因为午 ...
- 你不得不知道的 MySQL 优化原理
目录 MySQL逻辑架构 MySQL查询过程 客户端/服务端通信协议 查询缓存 查询优化 查询执行引擎 返回结果给客户端 总结 性能优化建议 Scheme设计与数据类型优化 创建高性能索引 索引相关的 ...
- 【Azure 存储服务】Blob中数据通过Stream Analytics导出到SQL/Cosmos DB
问题描述 Json格式的数据目前是存储在Azure Blob中,如何将这些数据Load到Sql DB和CosmosDB中呢? 测试方案 使用Azure流分析服务(Stream Analytics)功能 ...
- 【Azure Developer】在Azure Storage Account的两个Blob可以同步吗?可以跨订阅拷贝吗?
问题描述 不同订阅下的Azure Storage Account中Blob资源可以同步吗? 解决方案 可以.通过Azure 官方推荐的Storage Account工具来完成 Copy/Paste 操 ...
- SpringCloud Sentinel使用
1. 简介 Sentinel 是面向分布式服务架构的流量控制组件,主要以流量为切入点,从限流.流量整形.熔断降级.系统负载保护.热点防护等多个维度来帮助开发者保障微服务的稳定性.替换原先Hystrix ...
- 2022 Gartner RPA魔力象限,弘玑Cyclone位置飞跃国产RPA进击全球
文/王吉伟 7月25日,国际权威分析机构Gartner发布了2022全球RPA魔力象限报告(Gartner RPA MQ),UiPath.Automation Anywhere.微软等来自全球的15家 ...
- php本地上传文件类
/** * Class UploadFile * @author fengzi */ class UploadFile { public $error = array(); //上传前的error信息 ...
- 摆脱鼠标系列 Trigger Suggest 快捷键 改成 Shift + Space
摆脱鼠标系列 Trigger Suggest 快捷键 改成 Shift + Space 看marp插件的时候,发现用ctrl + space 自动提示,但是我这里是输入法