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 ...
随机推荐
- Linux实现VLAN
交换机的端口有两种配置模式:Access和Trunk. Access口:端口属于VLAN,VLAN ID 1~4096.直接与计算机网卡相连,流入该口的数据包都被打上VLAN的标签. Trunk口:允 ...
- cxf配置
先记录一下,后期补充配置原因 原先的spring3.X(struts2)的时候配置cxf2.x没问题,基本就是在context.xml中加入 <import resource="cla ...
- Linux+Jenkins环境搭建
一.安装基础环境 1. yum -y install java-1.8.0-openjdk.x86_64 #安装1.8jdk 2. 查看java 版本 [root@localhost djanggo_ ...
- NET的基本用法
NET的基本用法 NET [ ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP | HELPMSG | LOCALGROUP ...
- dubbo多网卡时,服务提供者的错误IP注册到注册中心导致消费端连接不上
使用了虚拟机之后,启动了dubbo服务提供者应用,又连了正式环境的注册中心: 一旦dubbo获取的ip错误后, 这种情况即使提供者服务停掉,目前dubbo没有能力清除这类错误的提供者: (需要修改源码 ...
- Reading Lines from File in C++
Reading Lines from File in C++ In C++, istringstream has been used to read lines from a file. code: ...
- 通过 UC2000-VG-32G设备呼叫不进号问题排查
1.登陆设备管理页面: 呼叫发起时,呼叫状态显示振铃,但是不进号. 2.查看设备cdr. 3.得出结论:NO CARRIER 由于号码频繁呼叫次数太多运营商对其死锁.
- bash的基础特性
命令历史:history 环境变量: HISTSIZE: 命令历史的条数 HISTFILE:~/.bash_history HISTFILESIZE: 命令历史文件记录历史的条数 history -d ...
- JavaScript闭包函数&箭头函数调用与执行
一.标准的闭包函数 //一.标准的闭包函数 function A() { var i=0; ++i; console.log('i : ' + i); return function b() { re ...
- Codeforces Round #113 (Div. 2) B. Polygons Andrew求凸包
B. Polygons time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...