分析:https://www.bilibili.com/read/cv4777102

  1. #include <cstdio>
  2. #include <algorithm>
  3. using namespace std;
  4. const int MAXN=1e5+;
  5. struct node{int l,r,lazy,color;}t[MAXN*];
  6. int L,R,C,n,m,q;
  7. #define ls t[x].l
  8. #define rs t[x].r
  9. int count(int x){int ans=;for(;x;x>>=)if(x&)ans++;return ans;}
  10. void pushdown(int x){if(t[x].lazy)t[ls].lazy=t[rs].lazy=t[ls].color=t[rs].color=t[x].lazy,t[x].lazy=;}
  11. void update(int x){t[x].color=t[ls].color|t[rs].color;}
  12. void build(int x,int l,int r){
  13. if(l==r){t[x].color=;return;}
  14. int mid=(l+r)>>;t[x].l=(x<<),t[x].r=(x<<|);
  15. build(ls,l,mid),build(rs,mid+,r),update(x);
  16. }
  17. void update(int x,int l,int r){
  18. if(L<=l&&r<=R){t[x].color=t[x].lazy=<<(C-);return;}
  19. pushdown(x);int mid=(l+r)>>;
  20. if(L<=mid)update(ls,l,mid);
  21. if(R>mid)update(rs,mid+,r);
  22. update(x);
  23. }
  24. int query(int x,int l,int r){
  25. if(L<=l&&r<=R)return t[x].color;
  26. pushdown(x);int mid=(l+r)>>,ans=;
  27. if(L<=mid)ans|=query(ls,l,mid);
  28. if(R>mid)ans|=query(rs,mid+,r);
  29. return ans;
  30. }
  31. int main(){
  32. scanf("%d%d%d",&n,&m,&q),build(,,n);
  33. for(int a,b;q--;){
  34. char s[];scanf("%s",s);
  35. if(s[]=='C')scanf("%d%d%d",&a,&b,&C),L=min(a,b),R=max(a,b),update(,,n);
  36. else scanf("%d%d",&a,&b),L=min(a,b),R=max(a,b),printf("%d\n",count(query(,,n)));
  37. }
  38. return ;
  39. }

C++-POJ2777-Count Color[线段树][lazy标记][区间修改]的更多相关文章

  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(线段树区区+染色问题)

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

  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(线段树之成段更新)

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

  7. poj3468 线段树+lazy标记

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 92921   ...

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

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

  9. POJ3237 Tree(树剖+线段树+lazy标记)

    You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edges are numbe ...

随机推荐

  1. go单任务版爬虫

    go单任务版爬虫(爬取珍爱网) 爬虫总体算法 单任务版爬虫架构 任务 获取并打印所在城市第一页用户的详细信息 代码实现 /crawler/main.go package main import ( & ...

  2. linux cpp (接口与实现的分离)

    以下是 .h 文件,是接口. 以下是函数的实现 以下是主函数 首先是以上两个文件编译,不用编译头文件 g++ -c gradeBook.cpp g++ -c gradeBook.main.cpp 之后 ...

  3. Sublime Text 3 最新可用注册码(免破解)(转载)

    转载地址:https://sjolzy.cn/Sublime-Text-3-crack-registration-code.html 12年的时候分享过Sublime Text 2的注册码和破解方法. ...

  4. Beego 输出数据格式JSON、XML、JSONP

    JSON.XML.JSONP beego 当初设计的时候就考虑了 API 功能的设计,而我们在设计 API 的时候经常是输出 JSON 或者 XML 数据,那么 beego 提供了这样的方式直接输出: ...

  5. phyon tensorflow 安装(centos)

    1.phyon27 安装 1.1 下载 wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz 1.2  解压 tar -zxv ...

  6. IDA PRO

    链接:https://pan.baidu.com/s/1LTXhXra5Honpn3L9rfSOgA 提取码:7bwb 工具下载地址: https://www.jb51.net/softjc/5799 ...

  7. centos 7 安装 Vue

    一.安装npmyum install -y npm 二.更新组件yum update openssl 三.安装Vue最新稳定版本npm install vue最新稳定 CSP 兼容版本npm inst ...

  8. Error: cannot fetch last explain plan from PLAN_TABLE

    最近遇到了错误"Error: cannot fetch last explain plan from PLAN_TABLE",于是稍微研究了一下哪些场景下碰到这种错误,具体参考下面 ...

  9. 1.Docker Compose

    一.Docker Compose 简介 概述 Compose 项目是 Docker 官方的开源项目,负责实现对 Docker 容器集群的快速编排.从功能上看,跟 OpenStack 中的 Heat 十 ...

  10. 关于Windows系统下端口被占用的问题和task命令

    一.如何解决端口被占用的问题? 此时端口4444被进程占用,只要找到端口4444的进程,并且将进程kill掉即可. 开始--运行--cmd 进入命令提示符 输入netstat -aon 即可看到所有连 ...