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 ...
随机推荐
- shader学习路线
http://www.jianshu.com/p/7b9498e58659 http://blog.csdn.net/candycat1992/article/details/37882765
- Cache模拟器(CacheSim)
最近写了一个Cache的模拟器,由于平时空余时间比较分散,前前后后用了一周多的时间,基本实现的Cache的模拟功能(通过读取trace文件得到相应的命中率),能够实现直接映射.全相联.组相联三种 ...
- js时间显示设置
//对日期中部分小于10的数字前边添加0 function zero(s){ return s < 10 ? '0' + s: s; } var date=new Date(), year = ...
- IntelliJ IDEA 中properties中文显示问题
- SQL Server 自定义函数(1)把某一列多行的值拼接成一个字符串
) SET @resultstr='' SELECT @resultstr=@resultstr+'|'+[BaseImage] FROM dbo.life_fc PRINT @resultstr 示 ...
- [转载]ME51n,ME52n,ME53n屏幕增强
原文地址:ME51n,ME52n,ME53n屏幕增强作者:cyzhang811 http://blog.sina.com.cn/s/blog_721b218c0100zch9.html 使用增强:ME ...
- Tomcat编码问题
在Tomcat7中,默认URIEncoding="iso8859-1",get请求由于url会完全出现在地址栏,所以传递中文到后台会乱码,需要改成URIEncoding=" ...
- 转:Nginx配置指令location匹配符优先级和安全问题
转:http://www.jb51.net/article/47761.htm 使用nginx 很久了,它的性能高,稳定性表现也很好,得到了很多人的认可.特别是它的配置,有点像写程序一样,每行命令结尾 ...
- mke2fs/mks.etc3/fstab/mount指令
一.mke2fs指令mkfs.etc3 /dev/sdb1指令 主要新学习 cat /etc/filesystem //查看文件类型 mkfs. tab键有提示 //按照系统默认的值格式化 m ...
- B’QConf(北京软件质量大会)记
下午从公司加班回来,顺路到淘宝(大望路)参加B'QConf(北京软件质量大会).淘宝所在的国家广告产业园原来是一个菜市场,已经有大约6年没有到那一带活动了.之所以记得这么清楚,是因为6年前曾经从那里的 ...