[日常摸鱼][poj2777]Count Color-线段树
辣鸡会考考完啦哈哈哈哈
题意:一块板分成$L$块,每次给一段连续的块染色或者询问一段有几种颜色,颜色的范围$\leq 30$
我记得我好像做过一个类似的二维染色的问题…不过那个用树状数组直接过掉了…
这题颜色范围这么小的范围直接想到线段树了吧,直接把一个区间的颜色二进制按位压缩成一个状态,维护区间或
题面还特地说了可能$a>b$…然而我没看到
#include<cstdio>
const int N=100005;
inline int read()
{
int s=0,f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
return s*f;
}
int n,o,t;
int tr[N<<2],tag[N<<2];
char s[5];
inline void swap(int &a,int &b){int t=a;a=b;b=t;}
#define lson (node<<1)
#define rson (node<<1|1)
inline void push_up(int node)
{
tr[node]=tr[lson]|tr[rson];
}
inline void push_down(int node,int l,int r)
{
if(tag[node]==-1)return;
tag[lson]=tag[rson]=tag[node];
tr[lson]=tr[rson]=(1<<(tag[node]-1));
tag[node]=-1;
}
inline void build(int node,int l,int r)
{
tag[node]=-1;tr[node]=1;
if(l==r)return;
int mid=(l+r)>>1;
build(lson,l,mid);build(rson,mid+1,r);
}
inline void modify(int node,int l,int r,int ql,int qr,int v)
{
if(ql<=l&&r<=qr)
{
tag[node]=v;
tr[node]=(1<<(v-1));
return;
}push_down(node,l,r);
int mid=(l+r)>>1;
if(mid>=ql)modify(lson,l,mid,ql,qr,v);
if(mid+1<=qr)modify(rson,mid+1,r,ql,qr,v);
push_up(node);
}
inline int query(int node,int l,int r,int ql,int qr)
{
if(ql<=l&&r<=qr)return tr[node];
push_down(node,l,r);int res=0,mid=(l+r)>>1;
if(mid>=ql)res|=query(lson,l,mid,ql,qr);
if(mid+1<=qr)res|=query(rson,mid+1,r,ql,qr);
return res;
}
int main()
{
//freopen("input.in","r",stdin);
n=read();t=read();o=read();
build(1,1,n);
for(register int i=1;i<=o;i++)
{
scanf("%s",s+1);
if(s[1]=='C')
{
int a,b,c;a=read();b=read();c=read();
if(a>b)swap(a,b);modify(1,1,n,a,b,c);
}else{
int a,b;a=read();b=read();
if(a>b)swap(a,b);
int sum=query(1,1,n,a,b),res=0;
for(register int k=0;k<=32;k++)
{
if(sum&(1ll<<k))res++;
}printf("%d\n",res);
}
}
return 0;
}
[日常摸鱼][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 ...
随机推荐
- springboot中使用Filter、Interceptor和aop拦截REST服务
在springboot中使用rest服务时,往往需要对controller层的请求进行拦截或者获取请求数据和返回数据,就需要过滤器.拦截器或者切片. 过滤器(Filter):对HttpServletR ...
- 今天谁也别想阻止我好好学习!「CDR 6·18特惠倒计时2天!」
前几天小编刷抖音,一个以农夫山泉为创作背景的服装原创视频 让我为之一震 这个自称以捡瓶子为生的服装设计师 让我产生了极为浓烈的兴趣 细扒这位小姐姐的视频 她用身边的常见物品 脑洞大开的画出了一系列插画 ...
- word教程字体和段落设置
放大/缩小字号:1.选中文字-点击"大A"或"小A" 2.同时摁着ctrl+shift+>/ctrl+shift+<即可 设置标题与正文间距:鼠标放 ...
- jQuery 第五章 实例方法 详解内置队列queue() dequeue() 方法
.queue() .dequeue() .clearQueue() ------------------------------------------------------------------ ...
- mongodb查询前10条
mongo可以通过时间或者通过id来判断上一条记录或者下一条记录,我是通过id 前10条 db.数据库名称.find({ '_id': { '$lt': ids } }).sort({_id: -1} ...
- [从源码学设计]蚂蚁金服SOFARegistry之消息总线
[从源码学设计]蚂蚁金服SOFARegistry之消息总线 目录 [从源码学设计]蚂蚁金服SOFARegistry之消息总线 0x00 摘要 0x01 相关概念 1.1 事件驱动模型 1.1.1 概念 ...
- mysql给用户赋予所有权限
mysql给用户赋予所有权限(包括远程连接) 我们给mysql新创建的用户,希望它拥有更多权限,比如远程连接,方便我们操作,可以使用如下命令: GRANT ALL PRIVILEGES ON *.* ...
- 发现了一个关于 gin 1.3.0 框架的 bug
gin 1.3.0 框架 http 响应数据错乱问题排查 问题概述 客户端同时发起多个http请求,gin接受到请求后,其中一个接口响应内容为空,另外一个接口响应内容包含接口1,接口2的响应内容,导致 ...
- 音视频入门-18-手动生成一张GIF图片
* 音视频入门文章目录 * GIF 编码知识 GIF 包含的数据块: 文件头(Header) 逻辑屏幕标识符(Logical Screen Descriptor) 全局颜色表(Global Color ...
- PyQt学习随笔:Qt中Model/View中的怎么构造View匹配的Model
老猿Python博文目录 老猿Python博客地址 在<PyQt学习随笔:Qt中Model/View相关的主要类及继承关系>介绍了Model/View架构的主要类,在实际使用时,view相 ...