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 ...
随机推荐
- c语言数据结构:01背包问题-------动态规划
两天的时间都在学习动态规划:小作业(01背包问题:) 数据结构老师布置的这个小作业还真是让人伤头脑,自己实在想不出来了便去网上寻找讲解,看到一篇不错的文章: http://www.cnblogs.co ...
- ERROR 1130: Host 'root@localhost' is not allowed to connect to MySQL server
连接mysql时遇到的错误. 原因:该用户没有权限连接访问mysql数据库 解决方法:网站上搜了好多,试了都没有用.最终在登陆的信息页面用root用户登陆时不输入root密码即可.
- javaSE之线程联合
首先定义 : 一个线程A在占有CPU资源期间 ,可以让其他线程调用join()和本线程联合. 嗯哈,像书本这个列子: 如: B.join(); 我们称A在运行期间联合了B, 如果线程A在占有CPU资源 ...
- MVC 特殊字符的显示
@(new HtmlString(HttpUtility.HtmlDecode(GPDetail.SimpleDescription)))
- SQL Server数据库(SQL Sever语言 事务)
事务:保障流程的完整执行保证程序某些程序在运行时同时成功同时失败,保证程序的安全性 begin tran --在流程开始的位置加 --此处写SQL语句 if @@error>0 --ERRORS ...
- HTML:表格与表单
一.图片热点:规划出图片上的一个区域,可以做出超链接,直接点击图片区域就可以完成跳转的效果. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...
- Codeforces Round #313 (Div. 2) C. Gerald's Hexagon
C. Gerald's Hexagon time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- ORACLE数据泵还原(IMPDP命令)【转】
Oracle数据库还原IMPDP命令是相对于EXPDP命令的,方向是反向的.即对于数据库备份进行还原操作.一.知晓IMPDP命令 ? C:\>impdp -help Import: Rele ...
- apache2.4域名配置参数
apache2.4和 2.2版本的配置有区别 2.4的配置如下 <VirtualHost *:80>DocumentRoot /www/web/projectServerName www. ...
- Window["aaa"]这个在JS里是什么意思?
答案:定义一个全局的变量 aaa,这个的方式是数组,实际上是等于 window.aaa