C++-POJ2777-Count Color[线段树][lazy标记][区间修改]
分析: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标记][区间修改]的更多相关文章
- [poj2777] Count Color (线段树 + 位运算) (水题)
发现自己越来越傻逼了.一道傻逼题搞了一晚上一直超时,凭啥子就我不能过??? 然后发现cin没关stdio同步... Description Chosen Problem Solving and Pro ...
- POJ2777 Count Color 线段树区间更新
题目描写叙述: 长度为L个单位的画板,有T种不同的颜料.现要求按序做O个操作,操作分两种: 1."C A B C",即将A到B之间的区域涂上颜色C 2."P A B&qu ...
- Count Color(线段树+位运算 POJ2777)
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39917 Accepted: 12037 Descrip ...
- poj 2777 Count Color(线段树区区+染色问题)
题目链接: poj 2777 Count Color 题目大意: 给出一块长度为n的板,区间范围[1,n],和m种染料 k次操作,C a b c 把区间[a,b]涂为c色,P a b 查 ...
- poj 2777 Count Color(线段树)
题目地址:http://poj.org/problem?id=2777 Count Color Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- POJ 2777 Count Color(线段树之成段更新)
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 33311 Accepted: 10058 Descrip ...
- poj3468 线段树+lazy标记
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 92921 ...
- poj 2777 Count Color - 线段树 - 位运算优化
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 42472 Accepted: 12850 Description Cho ...
- 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 ...
随机推荐
- CentOS7.6安装MySQL8.0(图文详细篇)
目录 一.安装前准备 二.安装MySQL 三.设置远程登录 四.安装问题解决 五.设置MySQL开机自启 一.安装前准备 1.在官网下载MySQL安装包(注意下载的安装包类型) 2.查看是否安装ma ...
- go 并发编程
进程 线程 协程 设置golang运行cpu数 1.主线程和协程同时执行 package main import ( "fmt" "strconv" " ...
- You are my great sunshine
"何为孤寂?" "清风,艳日,无笑意." "可否具体?" "左拥,右抱,无情欲." "可否再具体?" ...
- 使用springboot整合ActiveMQ
结构图 第一步:导入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifact ...
- 关于map 的几种方式
java为数据结构中的映射定义了一个接口java.util.Map;它有四个实现类,分别是==HashMap Hashtable LinkedHashMap 和TreeMap.== Map主要用于存储 ...
- 通俗易懂的RESTful API实践详解(含代码)
来源:点击进入 点击上方链接,版面更好 一.什么是RESTful REST 是面向资源的,这个概念非常重要,而资源是通过 URI 进行暴露,URI 的设计只要负责把资源通过合理方式暴露出来就可以了,对 ...
- 用R实现范式编程
面向函数范式编程(Functional programming) 模拟简单的随机过程 模拟一个简单的随机过程:从N~(0,1)标准正态分布中产生100个随机值,反复5次得到一个list,再以每个lis ...
- ag.百家下三路怎么看,如何玩好百家了
\/Q同号3908914.百家作为风靡全球的一款游戏,这么多年长盛不衰,是世界各地玩家的心头所好,但是你真的知道怎么玩好百家吗?第一点呢就是心态问题,我个人认为心态好一切都好,光是心态就占了百分之五十 ...
- 关于FrameLayout中覆盖的问题
FrameLayout中xml文件中写在下方的控件会默认覆盖上方的控件,如图,我准备实现如下效果: 这时recyclerview就要写在前面 如果recyclerview写在下面就会覆盖掉我linea ...
- Auto-scaling scikit-learn with Apache Spark
来源:https://databricks.com/blog/2016/02/08/auto-scaling-scikit-learn-with-apache-spark.html Data scie ...