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

 #include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN=1e5+;
struct node{int l,r,lazy,color;}t[MAXN*];
int L,R,C,n,m,q;
#define ls t[x].l
#define rs t[x].r
int count(int x){int ans=;for(;x;x>>=)if(x&)ans++;return ans;}
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=;}
void update(int x){t[x].color=t[ls].color|t[rs].color;}
void build(int x,int l,int r){
if(l==r){t[x].color=;return;}
int mid=(l+r)>>;t[x].l=(x<<),t[x].r=(x<<|);
build(ls,l,mid),build(rs,mid+,r),update(x);
}
void update(int x,int l,int r){
if(L<=l&&r<=R){t[x].color=t[x].lazy=<<(C-);return;}
pushdown(x);int mid=(l+r)>>;
if(L<=mid)update(ls,l,mid);
if(R>mid)update(rs,mid+,r);
update(x);
}
int query(int x,int l,int r){
if(L<=l&&r<=R)return t[x].color;
pushdown(x);int mid=(l+r)>>,ans=;
if(L<=mid)ans|=query(ls,l,mid);
if(R>mid)ans|=query(rs,mid+,r);
return ans;
}
int main(){
scanf("%d%d%d",&n,&m,&q),build(,,n);
for(int a,b;q--;){
char s[];scanf("%s",s);
if(s[]=='C')scanf("%d%d%d",&a,&b,&C),L=min(a,b),R=max(a,b),update(,,n);
else scanf("%d%d",&a,&b),L=min(a,b),R=max(a,b),printf("%d\n",count(query(,,n)));
}
return ;
}

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. Dijkstra算法(Matlab实现)

    a = [,,,,,,]; % 起点节点 b = [,,,,,,]; % 终点节点 c = [,,,,,,]; % 对应权值 g = digraph(a,b,c); % 创建图 [path,dista ...

  2. HTML5基础-新增标签+新增属性+布局案例

    html5中常用的结构标签 article 文章 header 头部 nav 导航 section 区域 aside 侧边栏 hgroup 区块的相关信息 figure 定义一组内容及标题 figca ...

  3. P5367 【模板】康托展开

    我们的生活充满了未知与玄学 ---------------------------------------- 链接:P5367 ------------------------------------ ...

  4. lvm实现服务器磁盘空间合并

    1    LVM实现将2块磁盘总空间“合二为一”并挂载到同一目录 1.1   磁盘分区 首先查看磁盘信息,对未分区的磁盘进行分区处理(选择你要合并的盘,这里是对vdb.vdc). 如上图,可以看出有5 ...

  5. Cenos7下指定ftp用户限制在特定目录下(亲身实践)

    好了,废话不多说.上头下来个需求,让我给别人开个ftp账户,只能访问项目的目录,不能访问项目外的目录,就算cd切换目录也不行. 开始: 第一步;安装ftp,我用的是centos7,只需敲入命令 yum ...

  6. ASP.NET Identity系列教程-2【Identity入门】

    https://www.cnblogs.com/r01cn/p/5177708.html13 Identity入门 Identity is a new API from Microsoft to ma ...

  7. 微信小程序直播资料整理

    可以通过此脑图大概了解小程序直播内容:https://developers.weixin.qq.com/community/develop/article/doc/0002a62b3749f088fa ...

  8. 牛客寒假6-F十字阵列

    链接:https://ac.nowcoder.com/acm/problem/201986来源:牛客网 题目描述 小 Q 新学会了一种魔法,可以对一个 N行M列 的网格上的敌人造成伤害 第 i 次使用 ...

  9. 牛客寒假训练营2-C算概率

    思路 用 f(i,j) 来表示当前做了i道题,共做对了j道题 状态 f[i][j] = f[i-1][j] * (1-p[i]) + f[i-1][j-1] * p[i] 第一种:由于i-1时对了j题 ...

  10. mybatis插入嵌套对象

    今晚做项目遇上了一个需求,需要插入嵌套对象. 对象结构是这样的: public class RegisterMsg{ private  Header header; private short pro ...