[日常摸鱼][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 ...
随机推荐
- gcc和g++理解
环境使用的编译器版本是是gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39) 编译使用了c++11标准的程序时不能通过. 先放解决方法:g++ -std=c++11 ...
- java面试必问:多线程的实现和同步机制,一文帮你搞定多线程编程
前言 进程:一个计算机程序的运行实例,包含了需要执行的指令:有自己的独立地址空间,包含程序内容和数据:不同进程的地址空间是互相隔离的:进程拥有各种资源和状态信息,包括打开的文件.子进程和信号处理. 线 ...
- CentOS 防火墙常用命令
1.查看防火墙状态: firewall-cmd --state 2.启动防火墙 systemctl start firewalld 3.关闭防火墙 systemctl stop firewalld 4 ...
- Spring Framework 5.0简述
从Spring框架5.0开始,Spring需要JDK 8+ (Java SE 8+),并且已经为JDK 9提供了现成的支持. Spring框架还支持依赖注入(JSR 330)和通用注释(JSR 250 ...
- 通过 GraalVM 将 Java 程序编译成本地机器码!
前言 2018年4月,Oracle Labs新公开了一项黑科技:Graal VM. 这是一个在HotSpot虚拟机基础上增强而成的跨语言全栈虚拟机,可以作为"任何语言"的运行平台使 ...
- 冲刺随笔——Day_Six
这个作业属于哪个课程 软件工程 (福州大学至诚学院 - 计算机工程系) 这个作业要求在哪里 团队作业第五次--Alpha冲刺 这个作业的目标 团队进行Alpha冲刺 作业正文 正文 其他参考文献 无 ...
- 深圳-2020-java面试题分享
记录一下最近面试接触的面试题. 深圳掌众传媒: union 和union all区别 union:对两个结果集进行并集操作,不包括重复行,同时进行默认规则的排序: union All:对两个结果集进行 ...
- oracle 流程控制句式
--for loop declare val number(10):=0; begin for val in 0..10 loop dbms_output.put_line('val='||val); ...
- IdentityServer4系列 | 客户端凭证模式
一.前言 从上一篇关于 快速搭建简易项目中,通过手动或者官方模板的方式简易的实现了我们的IdentityServer授权服务器搭建,并做了相应的配置和UI配置,实现了获取Token方式. 而其中我们也 ...
- PyQt(Python+Qt)学习随笔:QListView的selectionRectVisible属性
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 QListView的selectionRectVisible属性用于控制视图中的选择矩形框是否可见, ...