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单位之间的 ...
随机推荐
- 推荐系统评测指标—准确率(Precision)、召回率(Recall)、F值(F-Measure)
下面简单列举几种常用的推荐系统评测指标: 1.准确率与召回率(Precision & Recall) 准确率和召回率是广泛用于信息检索和统计学分类领域的两个度量值,用来评价结果的质量.其中精度 ...
- [CodeForces - 197A] A - Plate Game
A - Plate Game You've got a rectangular table with length a and width b and the infinite number of p ...
- hdu多校1002 Balanced Sequence
Balanced Sequence Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s) ...
- Qt Widgets——子区域和子窗口
QMdiArea 一般使用于主窗口QMainWindow,用于容纳多个子窗口QMdiSubWindow qt creator 3.0的设计师有MdiArea可直接拖入使用. 界面如下,图中灰色框即是个 ...
- 使用Postman在Chrome下进行rest请求测试
1.首先下载postman,我已经下载好,放在云盘里了. http://pan.baidu.com/s/1c1YoGKS 密码 dgfw 2.打开Chrome,点击更多工具->扩展程序~打开. ...
- The type java.lang.Object cannot be resolved
有时候在Eclipse中打开或者导入项目时会出现标题字样的问题:The type java.lang.Object cannot be resolved. It is indirectly refer ...
- ci框架多语言切换
1.多语言切换首先配置config文件默认语言 2.创建自己的语言包:language chinese english目录下的语言包文件名必须以 xx_lang.php 可根据自己的需求创建数组: ...
- 【例子】log4j.properties例子讲解
log4j.rootLogger=info, ServerDailyRollingFile, stdout log4j.appender.ServerDailyRollingFile=org.apac ...
- learning shell display alert function
[Purpose] Shell print function base on err info wrn ext output level [Eevironment] U ...
- OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/django'
http://blog.csdn.net/qq_34078897/article/details/50821553 权限问题,sudo