POJ2777-Count Color (线段树)
题目传送门:http://poj.org/problem?id=2777
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 45259 | Accepted: 13703 |
Description
There is a very long board with length L centimeter, L is a positive integer, so we can evenly divide the board into L segments, and they are labeled by 1, 2, ... L from left to right, each is 1 centimeter long. Now we have to color the board - one segment with only one color. We can do following two operations on the board:
1. "C A B C" Color the board from segment A to segment B with color C.
2. "P A B" Output the number of different colors painted between segment A and segment B (including).
In our daily life, we have very few words to describe a color (red, green, blue, yellow…), so you may assume that the total number of different colors T is very small. To make it simple, we express the names of colors as color 1, color 2, ... color T. At the beginning, the board was painted in color 1. Now the rest of problem is left to your.
Input
Output
Sample Input
2 2 4
C 1 1 2
P 1 2
C 2 2 2
P 1 2
Sample Output
2
1 线段树对区间操作,简单题
给你一段L长的线让你染色,有T中颜色,共有O次命令,
命令分为
C:给x到y染成c色
P:看x到y一共有多少种颜色
#include<stdio.h>
#include<string.h>
int cc[];
struct A{
int l,r,c;
}t[*+];
void bulid(int p,int l,int r)
{
t[p].l=l;t[p].r=r;t[p].c=;
if(l==r)
return ;
int mid=(t[p].l+t[p].r)>>;
bulid(p*,l,mid);
bulid(p*+,mid+,r);
}
void cha(int l,int r,int c,int p)
{
if(t[p].l==l&&t[p].r==r)
{
t[p].c=c;
return ;
}
if(t[p].c==c)
return ;
if(t[p].c!=-)
{
t[p*].c=t[p].c;
t[p*+].c=t[p].c;
t[p].c=-; }int mid=(t[p].l+t[p].r)>>;
if(r<=mid)
{
cha(l,r,c,p*);
}
else if(l>mid)
{
cha(l,r,c,p*+);
}
else
{
cha(l,mid,c,p*);
cha(mid+,r,c,p*+);
}
}
void se(int l,int r,int p)
{
if(t[p].c!=-)
{
cc[t[p].c]=;
// printf("!%d\n",t[p].c);
return ;
}
int mid=(t[p].l+t[p].r)>>;
if(r<=mid)
{
se(l,r,p*);
}
else if(l>mid)
{
se(l,r,p*+);
}
else
{
se(l,mid,p*);
se(mid+,r,p*+); }
}
int main()
{
int l,t,o,i,j,a,b,c;
char aa;
while(scanf("%d%d%d",&l,&t,&o)!=EOF)
{
bulid(,,l);
while(o--)
{
getchar();
aa=getchar(); if(aa=='C')
{
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
a=a^b;
b=a^b;
a=a^b;
}
cha(a,b,c,);
}
else if(aa=='P')
{
scanf("%d%d",&a,&b);
if(a>b)
{
a=a^b;
b=a^b;
a=a^b;
}
memset(cc,,sizeof(cc));
se(a,b,);
int sun=;
for(j=;j<=t;j++)
{
if(cc[j]==)
sun++;
} printf("%d\n",sun); }
} }
return ;
}
POJ2777-Count Color (线段树)的更多相关文章
- [poj2777] Count Color (线段树 + 位运算) (水题)
发现自己越来越傻逼了.一道傻逼题搞了一晚上一直超时,凭啥子就我不能过??? 然后发现cin没关stdio同步... Description Chosen Problem Solving and Pro ...
- POJ2777 Count Color 线段树区间更新
题目描写叙述: 长度为L个单位的画板,有T种不同的颜料.现要求按序做O个操作,操作分两种: 1."C A B C",即将A到B之间的区域涂上颜色C 2."P A B&qu ...
- Count Color(线段树+位运算 POJ2777)
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39917 Accepted: 12037 Descrip ...
- POJ 2777 Count Color(线段树之成段更新)
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 33311 Accepted: 10058 Descrip ...
- poj 2777 Count Color(线段树)
题目地址:http://poj.org/problem?id=2777 Count Color Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- poj 2777 Count Color(线段树区区+染色问题)
题目链接: poj 2777 Count Color 题目大意: 给出一块长度为n的板,区间范围[1,n],和m种染料 k次操作,C a b c 把区间[a,b]涂为c色,P a b 查 ...
- poj 2777 Count Color(线段树、状态压缩、位运算)
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 38921 Accepted: 11696 Des ...
- poj 2777 Count Color - 线段树 - 位运算优化
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 42472 Accepted: 12850 Description Cho ...
- POJ P2777 Count Color——线段树状态压缩
Description Chosen Problem Solving and Program design as an optional course, you are required to sol ...
- POJ 2777 Count Color (线段树成段更新+二进制思维)
题目链接:http://poj.org/problem?id=2777 题意是有L个单位长的画板,T种颜色,O个操作.画板初始化为颜色1.操作C讲l到r单位之间的颜色变为c,操作P查询l到r单位之间的 ...
随机推荐
- Oracle Cursor用法总结
cursor分为三种,一是直接声明为cursor变量,二是首先声明类型再声明变量,三是声明为sys_refcursor. (1)直接声明 declare cursor emp_cur is sele ...
- 本地仓库有jar包maven依然报错的原因
本地Maven仓库有所需jar包依然报错,missing……………… 既然有这个jar包为什么还会报错呢? 找到本地仓库后发现里面有一个_remote.repositories文件 问题在_remot ...
- loj 10000 活动安排
****这是一个贪心题,把结束时间排个序,然后留出更多的时间给后面的活动. #include<cstdio> #include<cstring> #include<alg ...
- 【转】JavaScript => TypeScript 入门
几个月前把 ES6 的特性都过了一遍,收获颇丰.现在继续来看看 TypesScript(下文简称为 “TS”).限于经验,本文一些总结如有不当,欢迎指正. 官网有这样一段描述: TypeScript ...
- kaggle信用卡欺诈看异常检测算法——无监督的方法包括: 基于统计的技术,如BACON *离群检测 多变量异常值检测 基于聚类的技术;监督方法: 神经网络 SVM 逻辑回归
使用google翻译自:https://software.seek.intel.com/dealing-with-outliers 数据分析中的一项具有挑战性但非常重要的任务是处理异常值.我们通常将异 ...
- MySQL修改root密码教程
1.记得密码但想要更新密码 mysql -uroot -p #使用当前密码登录mysql update MySQL.user set password=PASSWORD('新密码') where Us ...
- Qt样式表都有哪些属性可以设置
我们可以在Qt助手中输入Qt Style Sheets Reference然后选择List of Pseudo-States 项查看Qt控件支持的所有状态. 附几个参考学习的博客: https://b ...
- Java Web(二) Servlet详解
什么是Servlet? Servlet是运行在Web服务器中的Java程序.Servlet通常通过HTTP(超文本传输协议)接收和响应来自Web客户端的请求.Java Web应用程序中所有的请求-响应 ...
- python 自然语言处理(三)____条件频率分布
条件频率分布就是频率分布的集合,每个频率分布有一个不同的“条件”,这个条件通常是文本的类别.当语料文本分为几类(文体,主题,作者等)时,可以计算每个类别独立的频率分布,这样,就可以通过条件频率分布研究 ...
- 阿里云免费申请https证书
申请地址 https://common-buy.aliyun.com/?spm=a2c4e.11153940.blogcont65199.22.30f968210RsUSx&commodi ...