辣鸡会考考完啦哈哈哈哈

题意:一块板分成$L$块,每次给一段连续的块染色或者询问一段有几种颜色,颜色的范围$\leq 30$


我记得我好像做过一个类似的二维染色的问题…不过那个用树状数组直接过掉了…

这题颜色范围这么小的范围直接想到线段树了吧,直接把一个区间的颜色二进制按位压缩成一个状态,维护区间或

题面还特地说了可能$a>b$…然而我没看到

  1. #include<cstdio>
  2. const int N=100005;
  3. inline int read()
  4. {
  5. int s=0,f=1;char c=getchar();
  6. while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
  7. while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
  8. return s*f;
  9. }
  10. int n,o,t;
  11. int tr[N<<2],tag[N<<2];
  12. char s[5];
  13. inline void swap(int &a,int &b){int t=a;a=b;b=t;}
  14. #define lson (node<<1)
  15. #define rson (node<<1|1)
  16. inline void push_up(int node)
  17. {
  18. tr[node]=tr[lson]|tr[rson];
  19. }
  20. inline void push_down(int node,int l,int r)
  21. {
  22. if(tag[node]==-1)return;
  23. tag[lson]=tag[rson]=tag[node];
  24. tr[lson]=tr[rson]=(1<<(tag[node]-1));
  25. tag[node]=-1;
  26. }
  27. inline void build(int node,int l,int r)
  28. {
  29. tag[node]=-1;tr[node]=1;
  30. if(l==r)return;
  31. int mid=(l+r)>>1;
  32. build(lson,l,mid);build(rson,mid+1,r);
  33. }
  34. inline void modify(int node,int l,int r,int ql,int qr,int v)
  35. {
  36. if(ql<=l&&r<=qr)
  37. {
  38. tag[node]=v;
  39. tr[node]=(1<<(v-1));
  40. return;
  41. }push_down(node,l,r);
  42. int mid=(l+r)>>1;
  43. if(mid>=ql)modify(lson,l,mid,ql,qr,v);
  44. if(mid+1<=qr)modify(rson,mid+1,r,ql,qr,v);
  45. push_up(node);
  46. }
  47. inline int query(int node,int l,int r,int ql,int qr)
  48. {
  49. if(ql<=l&&r<=qr)return tr[node];
  50. push_down(node,l,r);int res=0,mid=(l+r)>>1;
  51. if(mid>=ql)res|=query(lson,l,mid,ql,qr);
  52. if(mid+1<=qr)res|=query(rson,mid+1,r,ql,qr);
  53. return res;
  54. }
  55. int main()
  56. {
  57. //freopen("input.in","r",stdin);
  58. n=read();t=read();o=read();
  59. build(1,1,n);
  60. for(register int i=1;i<=o;i++)
  61. {
  62. scanf("%s",s+1);
  63. if(s[1]=='C')
  64. {
  65. int a,b,c;a=read();b=read();c=read();
  66. if(a>b)swap(a,b);modify(1,1,n,a,b,c);
  67. }else{
  68. int a,b;a=read();b=read();
  69. if(a>b)swap(a,b);
  70. int sum=query(1,1,n,a,b),res=0;
  71. for(register int k=0;k<=32;k++)
  72. {
  73. if(sum&(1ll<<k))res++;
  74. }printf("%d\n",res);
  75. }
  76. }
  77. return 0;
  78. }

[日常摸鱼][poj2777]Count Color-线段树的更多相关文章

  1. [poj2777] Count Color (线段树 + 位运算) (水题)

    发现自己越来越傻逼了.一道傻逼题搞了一晚上一直超时,凭啥子就我不能过??? 然后发现cin没关stdio同步... Description Chosen Problem Solving and Pro ...

  2. POJ2777 Count Color 线段树区间更新

    题目描写叙述: 长度为L个单位的画板,有T种不同的颜料.现要求按序做O个操作,操作分两种: 1."C A B C",即将A到B之间的区域涂上颜色C 2."P A B&qu ...

  3. Count Color(线段树+位运算 POJ2777)

    Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39917 Accepted: 12037 Descrip ...

  4. POJ 2777 Count Color(线段树之成段更新)

    Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 33311 Accepted: 10058 Descrip ...

  5. poj 2777 Count Color(线段树)

    题目地址:http://poj.org/problem?id=2777 Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  6. poj 2777 Count Color(线段树区区+染色问题)

    题目链接:  poj 2777 Count Color 题目大意:  给出一块长度为n的板,区间范围[1,n],和m种染料 k次操作,C  a  b  c 把区间[a,b]涂为c色,P  a  b 查 ...

  7. poj 2777 Count Color(线段树、状态压缩、位运算)

    Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 38921   Accepted: 11696 Des ...

  8. poj 2777 Count Color - 线段树 - 位运算优化

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 42472   Accepted: 12850 Description Cho ...

  9. POJ P2777 Count Color——线段树状态压缩

    Description Chosen Problem Solving and Program design as an optional course, you are required to sol ...

随机推荐

  1. gcc和g++理解

    环境使用的编译器版本是是gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39) 编译使用了c++11标准的程序时不能通过. 先放解决方法:g++ -std=c++11 ...

  2. java面试必问:多线程的实现和同步机制,一文帮你搞定多线程编程

    前言 进程:一个计算机程序的运行实例,包含了需要执行的指令:有自己的独立地址空间,包含程序内容和数据:不同进程的地址空间是互相隔离的:进程拥有各种资源和状态信息,包括打开的文件.子进程和信号处理. 线 ...

  3. CentOS 防火墙常用命令

    1.查看防火墙状态: firewall-cmd --state 2.启动防火墙 systemctl start firewalld 3.关闭防火墙 systemctl stop firewalld 4 ...

  4. Spring Framework 5.0简述

    从Spring框架5.0开始,Spring需要JDK 8+ (Java SE 8+),并且已经为JDK 9提供了现成的支持. Spring框架还支持依赖注入(JSR 330)和通用注释(JSR 250 ...

  5. 通过 GraalVM 将 Java 程序编译成本地机器码!

    前言 2018年4月,Oracle Labs新公开了一项黑科技:Graal VM. 这是一个在HotSpot虚拟机基础上增强而成的跨语言全栈虚拟机,可以作为"任何语言"的运行平台使 ...

  6. 冲刺随笔——Day_Six

    这个作业属于哪个课程 软件工程 (福州大学至诚学院 - 计算机工程系) 这个作业要求在哪里 团队作业第五次--Alpha冲刺 这个作业的目标 团队进行Alpha冲刺 作业正文 正文 其他参考文献 无 ...

  7. 深圳-2020-java面试题分享

    记录一下最近面试接触的面试题. 深圳掌众传媒: union 和union all区别 union:对两个结果集进行并集操作,不包括重复行,同时进行默认规则的排序: union All:对两个结果集进行 ...

  8. oracle 流程控制句式

    --for loop declare val number(10):=0; begin for val in 0..10 loop dbms_output.put_line('val='||val); ...

  9. IdentityServer4系列 | 客户端凭证模式

    一.前言 从上一篇关于 快速搭建简易项目中,通过手动或者官方模板的方式简易的实现了我们的IdentityServer授权服务器搭建,并做了相应的配置和UI配置,实现了获取Token方式. 而其中我们也 ...

  10. PyQt(Python+Qt)学习随笔:QListView的selectionRectVisible属性

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 QListView的selectionRectVisible属性用于控制视图中的选择矩形框是否可见, ...