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 ...
随机推荐
- go单任务版爬虫
go单任务版爬虫(爬取珍爱网) 爬虫总体算法 单任务版爬虫架构 任务 获取并打印所在城市第一页用户的详细信息 代码实现 /crawler/main.go package main import ( & ...
- linux cpp (接口与实现的分离)
以下是 .h 文件,是接口. 以下是函数的实现 以下是主函数 首先是以上两个文件编译,不用编译头文件 g++ -c gradeBook.cpp g++ -c gradeBook.main.cpp 之后 ...
- Sublime Text 3 最新可用注册码(免破解)(转载)
转载地址:https://sjolzy.cn/Sublime-Text-3-crack-registration-code.html 12年的时候分享过Sublime Text 2的注册码和破解方法. ...
- Beego 输出数据格式JSON、XML、JSONP
JSON.XML.JSONP beego 当初设计的时候就考虑了 API 功能的设计,而我们在设计 API 的时候经常是输出 JSON 或者 XML 数据,那么 beego 提供了这样的方式直接输出: ...
- phyon tensorflow 安装(centos)
1.phyon27 安装 1.1 下载 wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz 1.2 解压 tar -zxv ...
- IDA PRO
链接:https://pan.baidu.com/s/1LTXhXra5Honpn3L9rfSOgA 提取码:7bwb 工具下载地址: https://www.jb51.net/softjc/5799 ...
- centos 7 安装 Vue
一.安装npmyum install -y npm 二.更新组件yum update openssl 三.安装Vue最新稳定版本npm install vue最新稳定 CSP 兼容版本npm inst ...
- Error: cannot fetch last explain plan from PLAN_TABLE
最近遇到了错误"Error: cannot fetch last explain plan from PLAN_TABLE",于是稍微研究了一下哪些场景下碰到这种错误,具体参考下面 ...
- 1.Docker Compose
一.Docker Compose 简介 概述 Compose 项目是 Docker 官方的开源项目,负责实现对 Docker 容器集群的快速编排.从功能上看,跟 OpenStack 中的 Heat 十 ...
- 关于Windows系统下端口被占用的问题和task命令
一.如何解决端口被占用的问题? 此时端口4444被进程占用,只要找到端口4444的进程,并且将进程kill掉即可. 开始--运行--cmd 进入命令提示符 输入netstat -aon 即可看到所有连 ...