分析: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. 【pattern】设计模式(3) - Observer观察者模式

    源码地址:https://github.com/vergilyn/design-patterns 另外一个大神很全的Github:https://github.com/iluwatar/java-de ...

  2. idea将普通项目转换为maven项目

    方式一 1.在项目根目录下,新建文件 pom.xml,并填写好内容. 2.在pom.xml文件上,右键 Add as Maven Project 或 在项目上,右键 Add Framework Sup ...

  3. java设计模式学习笔记--单一职责原则

    单一职责原则注意事项和细节 1.降低类的复杂度,一个类只负责一项职责 2.提高可读性,可维护性 3.降低变更引起的风险 4.通常情况下,我们应当遵守单一职责原则,只有逻辑足够简单,才可以在代码级违反单 ...

  4. exp导出含有双引号的表

    由于ORACLE默认的表名都是不区分大小写,在创建表时,在数据字典中存储的表名为大写.在有些情况下,如果创建的表在表名上加上双引号("),则创建的表其表名在数据字典中不作转换.比如 SQL& ...

  5. c#FTP基本使用

    public class FtpHelper { //基本设置 private static string ftppath = @"ftp://" + "192.168. ...

  6. redis的一些常见面试题

    1 .在项目中缓存是如何使用的? 2.为啥在项目里要用缓存呢? 用缓存,主要用途,高性能和高并发 高性能: 场景举例:假如有这么一个操作,用户发起请求,操作数据库,查出结果,耗时600ms,然后这个结 ...

  7. Auto-scaling scikit-learn with Apache Spark

    来源:https://databricks.com/blog/2016/02/08/auto-scaling-scikit-learn-with-apache-spark.html Data scie ...

  8. TChart-数据编辑(TChartListBox,TeeCommander)

    先上图 功能代码: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Contr ...

  9. Python带你来一次说走就走的环球旅行

      image 1.目 标 场 景 十一长假,相信大部分的朋友这会应该是在全国各地浪或者是在浪的路上,朋友圈成为你们表演的场所. 当然,也有一小戳朋友是选择家里蹲,你们是否感觉到无聊?是否想出去浪,参 ...

  10. Android_ExpandableListView

    实现效果: 类似于QQ联系人列表 相关属性: android:childDivider:指定各组内子类表项之间的分隔条,图片不会完全显示, 分离子列表项的是一条直线 android:childIndi ...