POJ2777(线段树裸题)
题目:http://poj.org/problem?id=2777
别忘了各地的return;
有可能输入的L<R,手动swap;
似乎是多组输入?
pushup和pushdown的位置。
(原来pushup只有一行)
要开四倍数组。是这种写法的原因吧。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=;
int n,m,q,L,R,co;
char ch;
long long col[N],lazy[N];
void pushdown(int cnt)
{
if(lazy[cnt])
{
col[cnt*]=lazy[cnt];
col[cnt*+]=lazy[cnt];
lazy[cnt*]=lazy[cnt];
lazy[cnt*+]=lazy[cnt];
lazy[cnt]=;
}
}
void pushup(int cnt)
{
col[cnt]=(col[cnt*]|col[cnt*+]);
}
void add(int l,int r,int cnt)
{
if(l>=L&&r<=R)
{
col[cnt]=co;
lazy[cnt]=co;
return;
}
pushdown(cnt);
int mid=(l+r)/;
if(mid>=L)add(l,mid,cnt*);
if(mid<R)add(mid+,r,cnt*+);
pushup(cnt);
}
long long query(int l,int r,int cnt)
{
if(l>=L&&r<=R)
{
return col[cnt];
}
long long ans=;
pushdown(cnt);
int mid=(l+r)/;
if(mid>=L)ans|=query(l,mid,cnt*);
if(mid<R)ans|=query(mid+,r,cnt*+);
return ans;
}
void build(int l,int r,int cnt)
{
col[cnt]=;
if(l==r)return;
int mid=(l+r)/;
build(l,mid,cnt*);
build(mid+,r,cnt*+);
}
int main()
{
while(scanf("%d%d%d",&n,&m,&q)!=EOF)
{
build(,n,);
memset(lazy,,sizeof lazy);
for(int i=;i<=q;i++)
{
scanf(" %c%d%d",&ch,&L,&R);
if(L>R)swap(L,R);//
if(ch=='C')
{
scanf("%d",&co);
co=(<<(co-));
add(,n,);
}
if(ch=='P')
{
int ret=;
long long ans=query(,n,);
while(ans)
{
ret+=(ans&);
ans>>=;
}
printf("%d\n",ret);
}
}
}
return ;
}
POJ2777(线段树裸题)的更多相关文章
- poj-2777线段树刷题
title: poj-2777线段树刷题 date: 2018-10-16 20:01:07 tags: acm 刷题 categories: ACM-线段树 概述 这道题是一道线段树的染色问题,,, ...
- POJ 3468 线段树裸题
这些天一直在看线段树,因为临近期末,所以看得断断续续,弄得有些知识点没能理解得很透切,但我也知道不能钻牛角尖,所以配合着刷题来加深理解. 然后,这是线段树裸题,而且是最简单的区间增加与查询,我参考了A ...
- BZOJ1067&P2471 [SCOI2007]降雨量[线段树裸题+细节注意]
dlntqlwsl 很裸的一道线段树题,被硬生生刷成了紫题..可能因为细节问题吧,我也栽了一次WA50分.不过这个隐藏条件真的对本菜鸡来说不易发现啊. 未知的年份连续的就看成一个就好了,把年份都离散化 ...
- CPU监控 线段树裸题
LINK:bzoj3064 此题甚好码了20min停下来思考的时候才发现不对的地方有点坑... 还真不好写来着 可这的确是线段树的裸题...我觉得我写应该没有什么大问题 不过思路非常的紊乱 如果是自己 ...
- 【LOJ6029】「雅礼集训 2017 Day1」市场(线段树裸题)
点此看题面 大致题意: 维护序列,支持区间加法,区间除法(向下取整),区间求\(min\)和区间求和. 线段树维护区间除法 区间加法.区间求\(min\)和区间求和都是线段树基本操作,因此略过不提. ...
- HDU1166 线段树裸题 区间求和
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 4893 线段树裸题
Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- cdoj 1324 卿学姐与公主 线段树裸题
卿学姐与公主 Time Limit: 2000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit St ...
- [HDU1754]I Hate It线段树裸题
http://acm.hdu.edu.cn/showproblem.php?pid=1754 解题关键:刚开始死活超时,最后发现竟然是ch,和t1.t2每次循环都定义的锅,以后养成建全局变量的习惯. ...
随机推荐
- OC 类的本质和分类
一.分类 (一)分类的基本知识 概念:Category 分类是OC特有的语言,依赖于类. 分类的作用:在不改变原来的类内容的基础上,为类增加一些方法. 添加一个分类: 文件结构图: 在分类中添加一 ...
- css 设置背景色
设置背景图 background:url($!{rc.contextPath}/assets/images/bady/date.png)repeat 50px center background:ur ...
- linux make virtual memory more efficient three components
Page Cache This is used to speed up access to images and data on disk. As pages are read into memory ...
- 申请和使用github共享代码
1.申请github帐号 https://github.com/join?source=header-home 2.创建项目 2.1 或者: 2.2 输入信息 2.3创建成功,地址及基本命令提示 3. ...
- python3 win10_x64 安装pcapy
稀里糊涂就装上了 大概记录一下都有什么. visual studio build tools 2015 下载地址: http://landinghub.visualstudio.com/visual- ...
- Nutch相关视频教程3
参考: http://www.cnblogs.com/huligong1234/p/3515214.html
- jquery ajax和php实现返回值 json类型
js页面 $.ajax({ type: “POST”, dataType: ‘json’, url: “add_vote.php”, data: “touid=”+uid+”&touserna ...
- spring学习笔记Core Technologies
Spring 框架最重要的是Ioc(Inversion of Control)容器,在这个基础之上衍生出了AOP(Aspect-Oriented Programming)技术,80/20法则,这货可以 ...
- html头标签meta实现refresh重定向
<html> <head> <meta http-equiv="content-type" content="text/html; char ...
- rocketmq集群安装,配置,测试
完整的安装包及demo请到百度云盘下载: 1.上传安装包 2.解压安装包 创建目录rocketmq mkdir -p /apps/install/rocketmq 解压到目录rocketmq tar ...