poj2777 线段树
//Accepted 4768 KB 391 ms
//线段树,延时标记的应用
//对于每一段,用一个int表示被着色的情况,change标记该段的颜色是否发生整体的改变,即这一段
//用没用被全部涂成令一种颜色
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
/**
* This is a documentation comment block
* 如果有一天你坚持不下去了,就想想你为什么走到这儿!
* @authr songt
*/
;
struct node
{
int l,r;
int color;
bool change;
}f[imax_n*];
void build(int t,int l,int r)
{
f[t].l=l;
f[t].r=r;
f[t].change=;
f[t].color=<<;
if (l==r)
{
return ;
}
;
build(*t,l,mid);
build(*t+,mid+,r);
}
int query(int t,int l,int r)
{
if (f[t].l==l && f[t].r==r)
{
return f[t].color;
}
)
{
f[*t].color=f[t].color;
f[*t+].color=f[t].color;
f[*t].change=f[*t+].change=;
f[t].change=;
}
;
*t,l,r);
else
{
*t+,l,r);
else
{
*t,l,mid);
*t+,mid+,r);
return t1|t2;
}
}
}
void update(int t,int l,int r,int c)
{
if (f[t].l==l && f[t].r==r)
{
f[t].change=;
f[t].color=<<c;
return ;
}
)
{
f[*t].color=f[t].color;
f[*t+].color=f[t].color;
f[t].change=;
f[*t].change=f[*t+].change=;
}
;
*t,l,r,c);
else
{
*t+,l,r,c);
else
{
update(*t,l,mid,c);
update(*t+,mid+,r,c);
}
}
f[t].color=f[*t].color|f[*t+].color;
}
int n;
int T;
int Q;
];
int x,y,c;
void swap(int &x,int &y)
{
int t=x;
x=y;
y=t;
}
void slove()
{
build(,,n);
;i<=Q;i++)
{
scanf("%s",s);
]=='C')
{
scanf("%d%d%d",&x,&y,&c);
if (x>y) swap(x,y);
update(,x,y,c);
}
else
{
scanf("%d%d",&x,&y);
if (x>y) swap(x,y);
,x,y);
;
)
{
ans++;
t-=(t&(-t));
}
printf("%d\n",ans);
}
}
}
int main()
{
while (scanf("%d%d%d",&n,&T,&Q)!=EOF)
{
slove();
}
;
}
poj2777 线段树的更多相关文章
- poj-2777线段树刷题
title: poj-2777线段树刷题 date: 2018-10-16 20:01:07 tags: acm 刷题 categories: ACM-线段树 概述 这道题是一道线段树的染色问题,,, ...
- Count Color poj2777 线段树
Count Color poj2777 线段树 题意 有一个长木板,现在往上面在一定区间内刷颜色,后来刷的颜色会掩盖掉前面刷的颜色,问每次一定区间内可以看到多少种颜色. 解题思路 这里使用线段树,因为 ...
- POJ2777(线段树涂色问题)
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 42828 Accepted: 12973 Des ...
- poj2777(线段树)
题目链接:https://vjudge.net/problem/POJ-2777 题意:有L块连续的板子,每块板子最多染一种颜色,有T种(<=30)颜色,刚开始将所有板子染成颜色1,O次操作(包 ...
- Count Color(线段树+位运算 POJ2777)
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39917 Accepted: 12037 Descrip ...
- [POJ2777]Count Color(线段树)
题目链接:http://poj.org/problem?id=2777 给你一个长为L想线段,向上面染色,颜色不超过30种,一共有O次操作,操作有两种: C a b c 在[a,b]上染上c颜色 P ...
- POJ-2777 Count Color(线段树,区间染色问题)
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 40510 Accepted: 12215 Descrip ...
- 几道简单的线段树入门题 POJ3264&&POJ3468&&POJ2777
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 40687 Accepted: 19137 ...
- POJ 2777(线段树)
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 42507 Accepted: 12856 Des ...
随机推荐
- 【CodeVS 1038】一元三次方程
题意 有形如:ax3+bx2+cx+d=0 这样的一个一元三次方程. 给出该方程中各项的系数(a,b,c,d 均为实数),并约定该方程存在三个不同实根(根的范围在-100至100之间),且根与根之差的 ...
- DI 之 3.4 Bean的作用域(捌)
3.4 Bean的作用域 什么是作用域呢?即"scope",在面向对象程序设计中一般指对象或变量之间的可见范围.而在Spring容器中是指其创建的Bean对象相对于其他Bean对 ...
- The Economist
The turning point in the process of growing up is when you discover the core of strength within yo ...
- laravel 自定义命令
1.自定义命令:将自定义命令保存在app/Console/Commands,也可以在composer.json文件配置自动加载,自由选择想要放置的地方 php artisan make:console ...
- CSS3:不可思议的border属性&Web字体图标Font Awesome
CSS3:不可思议的border属性 转载至——译文:不可思议的CSS border属性 原文:Magic of CSS border property Web字体图标Font Awesome 转载 ...
- 11 个用来创建图形和图表的 JavaScript 工具包
11个用来创建图形和图表的JavaScript工具包,方便开发者使用,喜欢的各位收藏一下吧! Aristochart DEMO|| Download Aristochart 是一个用来创建图形和图表的 ...
- --专访雷果国: 从1.5K到18K 一个程序员的5年成长之路--
导语:今年三月份,在CSDN博客和新浪微博上有一篇<从1.5K到18K,一个程序员的5年成长之路>被众人分享和传阅,这篇博文首先介绍了作者自学之初薄弱的基础,然后通过流水账形式分享了那个从 ...
- 联系 管理 Hibernate4+Spring JPA+SpringMVC+Volecity搭建web应用(三)
hibernate注解实体类示例 package cn.bdqn.smvc.entity; import java.io.Serializable; import javax.persistence. ...
- Java 读写方案
使用Java操作文本文件的方法详解 摘要: 最初java是不支持对文本文件的处理的,为了弥补这个缺憾而引入了Reader和Writer两个类 最初java是不支持对文本文件的处理的,为了弥补这个缺憾而 ...
- 深入入门正则表达式(java)
一.入门基础 1.元字符 很多人对正则表达式的印象就是乱码..许许多多的符号组合在一起,偶见单词,正则确实是这样的,所以下面我们要看看这些符号都是什么意思 有些符号不是大家看到的字面上的意思:比如“. ...