分析: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. 探究Redis两种持久化方式下的数据恢复

    对长期奋战在一线的后端开发人员来说,都知道redis有两种持久化方式RDB和AOF,虽说大家都知道这两种方式大概运作方式,但想必有实操的人不会太多. 这里是自己实操两种持久化方式的一点点记录. 先看以 ...

  2. windows本地安装Oracle数据库

    一.下载Oracle 11g R2 for Windows. 官方网站: https://www.oracle.com/database/technologies/oracle-database-so ...

  3. Linux 文件和目录操作命令(一)

    1.cd (change directory)切换到指定目录 - 返回上次目录 .. 返回上层目录 回车 返回主目录 / 根目录 2.cp (copy)复制文件或目录 -r -R 递归复制该目录及其子 ...

  4. 企业应用开发的大趋势,65%的应用开发将通过低代码完成 ZT

    全球知名的咨询公司Gartner于近日发表了最新版的<低代码开发平台魔力象限>,并在报告中指出,到2024年65%的应用开发工作都将通过低代码的方式完成.Gartner长期关注软件开发领域 ...

  5. Burp Suite 实战指南--说明书

       burp使用指南 网址:https://t0data.gitbooks.io/burpsuite/content/

  6. 剑指offer-面试题48-最长不含重复字符的子字符串-动态规划

    /* 题目: 最长不含重复字符的子字符串. */ /* 思路: f(i) = f(i-1) + 1,(未出现过当前字符,distance > f(i-1) distance,当前字符和上一次出现 ...

  7. 简单的leetcode题

    简单的leetcode题 环绕字符串中唯一的子字符串 把字符串 s 看作是\("abcdefghijklmnopqrstuvwxyz"\)的无限环绕字符串,所以 s 看起来是这样的 ...

  8. SPFA的优化一览

    目录 序 内容 嵬 序 spfa,是一个早已没人用的算法,就像那些麻木的人, 可谁有知道,他何时槃涅 一个已死的算法 ,重生 内容 关于\(NOI2018D1T1\)的惨案,为了以防spfa被卡. 关 ...

  9. 吴裕雄--天生自然HADOOP操作实验学习笔记:hive安装

    实验目的 了解hive的原理和安装方式 学习使用MySQL数据库 使用hive进行基本操作 实验原理 1.Hive Hive是一个数据仓库技术,包括解释器.编译器.优化器,一次将一个sql语句装化为m ...

  10. Pr常用的键盘操作

    Pr常用的键盘操作 Shift选中切开的小段 Alt复制效果