cf C. Knight Tournament
http://codeforces.com/contest/357/problem/C
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 300010
using namespace std; int n,m;
int l1,r1,x1;
struct node
{
int l,r;
int cover;
}tree[maxn*];
int x[maxn]; void build(int i,int l,int r)
{
tree[i].l=l;tree[i].r=r;
tree[i].cover=;
if(l==r) return ;
int mid=(l+r)>>;
build(i<<,l,mid);
build(i<<|,mid+,r);
}
void down(int i)
{
if(tree[i].l==tree[i].r) return ;
if(tree[i].cover>)
{
if(tree[i<<].cover==)
tree[i<<].cover=tree[i].cover;
if(tree[i<<|].cover==)
tree[i<<|].cover=tree[i].cover;
tree[i].cover=-;
}
}
void update(int i,int l,int r,int co)
{
if(tree[i].l==l&&tree[i].r==r)
{
if(tree[i].cover==)
{
tree[i].cover=co;
}
return ;
}
down(i);
int mid=(tree[i].l+tree[i].r)>>;
if(r<=mid)
{
update(i<<,l,r,co);
}
else if(l>mid)
{
update(i<<|,l,r,co);
}
else
{
update(i<<,l,mid,co);
update(i<<|,mid+,r,co);
}
} void search1(int i)
{
if(tree[i].l==tree[i].r)
{
x[tree[i].l]=tree[i].cover;
return;
}
down(i);
search1(i<<);
search1(i<<|);
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
build(,,n);
memset(x,,sizeof(x));
for(int i=; i<=m; i++)
{
scanf("%d%d%d",&l1,&r1,&x1);
if(l1==x1){
update(,l1+,r1,x1);
}
else if(r1==x1)
{
update(,l1,r1-,x1);
}
else
{
update(,l1,x1-,x1);
update(,x1+,r1,x1);
}
}
search1();
for(int i=; i<=n; i++)
{
if(i==)
printf("%d",x[i]);
else
printf(" %d",x[i]);
}
printf("\n");
}
return ;
}
cf C. Knight Tournament的更多相关文章
- CF 628A --- Tennis Tournament --- 水题
CF 628A 题目大意:给定n,b,p,其中n为进行比赛的人数,b为每场进行比赛的每一位运动员需要的水的数量, p为整个赛程提供给每位运动员的毛巾数量, 每次在剩余的n人数中,挑选2^k=m(m & ...
- CodeForce 356A Knight Tournament(set应用)
Knight Tournament time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Knight Tournament 合并区间
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the me ...
- Knight Tournament (set)
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the me ...
- CodeForces - 357C Knight Tournament 伪并查集(区间合并)
Knight Tournament Hooray! Berl II, the king of Berland is making a knight tournament. The king has a ...
- D - Knight Tournament(set)
Problem description Hooray! Berl II, the king of Berland is making a knight tournament. The king has ...
- codeforces 357C Knight Tournament(set)
Description Hooray! Berl II, the king of Berland is making a knight tournament. The king has already ...
- Codeforces Round #207 (Div. 1) A. Knight Tournament(STL)
脑子又卡了...来一发set的,STL真心不熟. #include <stdio.h> #include <string.h> #include <iostream> ...
- Knight Tournament
Codeforces Round #207 (Div. 1) A:http://codeforces.com/problemset/problem/356/A 题意:给你n匹马,然后有m场比赛.每场比 ...
随机推荐
- 8.2.1.1 Speed of SELECT Statements 加速SELECT 语句
8.2.1 Optimizing SELECT Statements 8.2.2 Optimizing Data Change Statements 8.2.3 Optimizing Database ...
- Android录音服务
MediaRecorder Mediarecorder=new MediaRecorder();//创建一个MediaRecorder对象 Mediarecorder.setAudioSource(M ...
- hdu5136:组合计数、dp
题目大意: 求直径长度为N的无根二叉树的个数(同构的只算一种) 分析: 分析发现直径长度不好处理!因此考虑把问题转化一下: 假设要求直径为N的二叉树 (1) 若N为偶数,将树从直径中点的边断开,则分成 ...
- 【转】H264视频编码级别说明profile level Encoder
版权声明:本文为博主原创文章,未经博主允许不得转载. 首先要阐明所谓的AVC其实就是H.264标准,是由ITU-T和ISO/IEC组成的联合视频组(JVT,Joint Video Team)一起开发的 ...
- JS中undefined与null的区别
1.概述: 在JavaScript中存在这样两种原始类型:Null与Undefined.这两种类型常常会使JavaScript的开发人员产生疑惑,在什么时候是Null,什么时候又是Undefined? ...
- [置顶] SQL注入问题
我们做系统,有没有想过,自己的容量很大的一个数据库就被很轻易的进入,并删除,是不是很恐怖的一件事.这就是sql注入. 一.SQL注入的概念 SQL注入攻击指的是通过构建特殊的输入作为参 ...
- IOS学习笔记(四)之UITextField和UITextView控件学习
IOS学习笔记(四)之UITextField和UITextView控件学习(博客地址:http://blog.csdn.net/developer_jiangqq) Author:hmjiangqq ...
- Rational AppScan 扫描大型网站
Rational AppScan 工作原理 Rational AppScan(简称 AppScan)其实是一个产品家族,包括众多的应用安全扫描产品,从开发阶段的源代码扫描的 AppScan sourc ...
- Java基础知识强化41:StringBuffer类之StringBuffer的反转功能
1. StringBuffer 的反转功能: public StringBuffer reverse(): 2. 案例演示: package cn.itcast_05; /* * StringBuff ...
- Sass函数--数字函数
数字函数简介 Sass 中的数字函数提要针对数字方面提供一系列的函数功能: percentage($value):将一个不带单位的数转换成百分比值: round($value):将数值四舍五入,转换成 ...