分析: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. P3945 | 三体问题 (天体物理+计算几何)

    最近终于把<三体Ⅰ·地球往事>和<三体Ⅱ·黑暗森林>看完了! 为了快点认识题目中的歌者文明,已经开始第三部了! 题目背景 @FirstLight0521 出题人在这里哦~ 三体 ...

  2. JSOI部分题解

    JSOI部分题解 JSOI2018 战争 问题转化为给定你两个凸包\(\mathbb S,\mathbb T\),每次独立的询问将\(\mathbb T\)中的每个点移动一个向量,问\(\mathbb ...

  3. .net core 3.0一个记录request和respose的中间件

    参考资料 https://www.cnblogs.com/wybin6412/p/10944077.html RequestResponseLog.cs using System; using Sys ...

  4. 纪中10日T3 2296. 神殿 bfs

    2296. 神殿 (File IO): input:temple.in output:temple.out 时间限制: 1500 ms  空间限制: 524288 KB  具体限制 Goto Prob ...

  5. vc6 保存文件卡住

    解决办法:删除工程文件中的三个文件,分别是:*.ncb  * .opt   * .plg引用链接:https://blog.csdn.net/lvxianlong123/article/details ...

  6. 【读书笔记】自然语言处理综述 -- 第四章 -- N元语法

    第四章 N元语法 本章开篇的两句话很有意思,代表了当时两个学派的思想和矛盾. 一句是"有史以来最伟大的语言学家"乔姆斯基说的:"句子的概率,在任何已知的对于这个术语的解释 ...

  7. Python学习笔记--协程asyncio

    协程的主要功能是单线程并发运行 假设有3个耗时不一样的任务.看看协程的效果. 先来看没有使用协程情况: #!/usr/bin/python3 # -*- coding:utf-8 -*- import ...

  8. hibernate.exception.GenericJDBCException: could not extract ResultSet 解决办法

    这句话翻译过来就是无法提取ResultSet 我在联查表的视图的时候发现的问题,明明之前好好的 那么你就得想想了 你再把错误信息往上翻翻,能不能看到   no viable alternative a ...

  9. C#MVC用ZXing.Net生成二维码/条形码

    开篇:zxing.net是.net平台下编解条形码和二维码的工具. 首先创建新项目 选择MVC模板  添加一个控制器  在项目引用中的引用ZXing 进行联网下载 控制器需要引用 后台控制器   pu ...

  10. jQuery笔记(四)jQuery中的动画

    jQuery最吸引人的地方莫过于能做出绚丽的动画了,也是能极大提高用户体验的地方,这次我们就来一探jQuery中的动画! 一. show()方法和hide()方法 show()方法与hide()方法是 ...