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所击败了(l<=x<=r),被击败的人立马退出游戏让你最后输出每个人是被谁击败的,最后那个胜利者没被
人击败就输出0
思路:他的每次修改的是一个区间的被击败的人,他而且只会记录第一次那个被击败的人,用线段树堕落标记的话他会记录最后一次的,所以我们倒着来修改,
然后因为那个区间里面还包含了自己,在线段树操作里面修改不太方便,所以我们采用把他拆分成两个区间来操作
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
struct tree
{
int l,r;
int val;
}d[*];
struct sss
{
int x,y,z;
}a[];
int n,m;
void buildtree(int cnt,int l,int r)
{
if(cnt>n*) return;
d[cnt].l=l;
d[cnt].r=r;
int mid=(l+r)/;
buildtree(cnt*,l,mid);
buildtree(cnt*+,mid+,r);
}
void pushdown(int cnt)
{
if(d[cnt].val!=){
d[cnt*].val=d[cnt].val;
d[cnt*+].val=d[cnt].val;
d[cnt].val=;
}
}
void update(int cnt,int l,int r,int val){
if(l==d[cnt].l&&r==d[cnt].r){
d[cnt].val=val;
return;
}
pushdown(cnt);
int mid=(d[cnt].l+d[cnt].r)/;
if(r<=mid) update(cnt*,l,r,val);
else if(l>mid) update(cnt*+,l,r,val);
else{
update(cnt*,l,mid,val);
update(cnt*+,mid+,r,val);
} }
void query(int cnt,int x)
{
if(d[cnt].l==d[cnt].r){
if(d[cnt].val==x) printf("0 ");
else printf("%d ",d[cnt].val);
return;
}
pushdown(cnt);
int mid=(d[cnt].l+d[cnt].r)/;
if(x<=mid) query(cnt*,x);
else query(cnt*+,x); }
int main()
{
cin>>n>>m;
for(int i=;i<m;i++){
cin>>a[i].x>>a[i].y>>a[i].z;
}
buildtree(,,n);
for(int i=m-;i>=;i--){
if(a[i].z->=a[i].x) //拆分成两个区间来修改
update(,a[i].x,a[i].z-,a[i].z);
if(a[i].z+<=a[i].y)
update(,a[i].z+,a[i].y,a[i].z);
}
for(int i=;i<=n;i++){
query(,i);
}
}
Codeforces Round #207 (Div. 1) A. Knight Tournament (线段树离线)的更多相关文章
- Codeforces Round #207 (Div. 1) A. Knight Tournament(STL)
脑子又卡了...来一发set的,STL真心不熟. #include <stdio.h> #include <string.h> #include <iostream> ...
- Codeforces Round #603 (Div. 2) E. Editor(线段树)
链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard pro ...
- Codeforces Round #244 (Div. 2) B. Prison Transfer 线段树rmq
B. Prison Transfer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/pro ...
- Codeforces Round #530 (Div. 2) F (树形dp+线段树)
F. Cookies 链接:http://codeforces.com/contest/1099/problem/F 题意: 给你一棵树,树上有n个节点,每个节点上有ai块饼干,在这个节点上的每块饼干 ...
- Codeforces Round #546 (Div. 2) E 推公式 + 线段树
https://codeforces.com/contest/1136/problem/E 题意 给你一个有n个数字的a数组,一个有n-1个数字的k数组,两种操作: 1.将a[i]+x,假如a[i]+ ...
- Codeforces Round #222 (Div. 1) D. Developing Game 线段树有效区间合并
D. Developing Game Pavel is going to make a game of his dream. However, he knows that he can't mak ...
- Codeforces Round #275 Div.1 B Interesting Array --线段树
题意: 构造一个序列,满足m个形如:[l,r,c] 的条件. [l,r,c]表示[l,r]中的元素按位与(&)的和为c. 解法: 线段树维护,sum[rt]表示要满足到现在为止的条件时该子树的 ...
- Codeforces Round #271 (Div. 2) F. Ant colony 线段树
F. Ant colony time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #406 (Div. 2) D. Legacy (线段树建图dij)
D. Legacy time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
随机推荐
- 0004-20180422-自动化第五章-python基础学习笔记
内容回顾:1.数据类型 2.for和while循环 continue break #如下循环将怎么打印结果? for i in range(1,10): print(i) for i in range ...
- HTML5中 audio标签的样式修改
由于html5的流行,现在移动端大多数的需求都可以使用audio来播放音频,但您可能只是需要很简单的播放/停止效果,但不同的浏览器上的audio样式却不尽人意,那么要怎么改变这个样式呢,其实它的原理比 ...
- JavaScript 初知
JavaScript 初知 1.JavaScript 独立的语言2.浏览器就是JavaScript的语言解释器3.JavaScript 代码存在于HTML中4.单行注释用“//”.多行注释 /* */ ...
- Docker Swarm 创建服务
Docker Swarm 创建服务 环境: 系统:Centos 7.4 x64 应用版本:Docker 18.09.0 管理节点:192.168.1.79 工作节点:192.168.1.78 工作节点 ...
- How to use “cat” command on “find” command's output?
You can do this with find alone using the -exec action: find /location -size 1033c -exec cat {} + {} ...
- python from entry to abandon2
学习Linux已经有大致两周了,依然感觉到自己仍然在运维的大门外徘徊.于是我想要找到一个在Linux之外的业余方向,可以以作为枯燥基础学习的调节.没过多久我就发现了Python可以说是钦定的选择,它作 ...
- CSS常用伪类
css伪类 :after 在元素后面插入内容 :hover 鼠标移入时进行 :before 在元素前面插入内容 :link 未选中的链接 :active 点击后产生什么变化 :nth-child 匹配 ...
- redis哨兵机制讲解
原文链接:https://blog.csdn.net/yswKnight/article/details/78158540 一.什么是哨兵机制? 答:Redis的哨兵(sentinel) 系统用于管理 ...
- Pandas 基础(9) - 组合方法 merge
首先, 还是以天气为例, 准备如下数据: df1 = pd.DataFrame({ 'city': ['newyork', 'chicago', 'orlando'], 'temperature': ...
- flink入门
wordCount POM文件需要导入的依赖: <dependency> <groupId>org.apache.flink</groupId> <artif ...