POJ 3225 (线段树 区间更新) Help with Intervals
这道题搞了好久,其实坑点挺多。。
网上找了许多题解,发现思路其实都差不多,所以就不在重复了。
推荐一篇比较好的题解,请戳这。
另外,如果因为可能要更新多次,但最终查询只需要一次,所以没有写pushup函数,仅有一个pushdown。
#include <cstdio> const int maxn = ;
//const int maxn = 10;
int qL, qR, op;
int setv[maxn << ], xorv[maxn << ];
bool in[maxn + ]; void pushdown(int o)
{
int lc = o*, rc = o*+;
if(setv[o] >= )
{
setv[lc] = setv[rc] = setv[o];
setv[o] = -;
xorv[lc] = xorv[rc] = ;
}
if(xorv[o])
{
if(setv[lc] >= ) setv[lc] ^= ; else xorv[lc] ^= ;
if(setv[rc] >= ) setv[rc] ^= ; else xorv[rc] ^= ;
xorv[o] = ;
}
} void update(int o, int L, int R, int qL, int qR)
{
if(qL <= L && qR >= R)
{
if(op == ) { setv[o] = xorv[o] = ; }
else if(op == ) { setv[o] = ; xorv[o] = ; }
else if(op == ) { if(setv[o] >= ) setv[o] ^= ; else xorv[o] ^= ; }
return;
}
int M = (L + R) / ;
pushdown(o);
if(qL <= M) update(o*, L, M, qL, qR);
if(qR > M) update(o*+, M+, R, qL, qR);
} void query(int o, int L, int R)
{
if(setv[o] >= )
{
if(setv[o] == ) for(int i = L; i <= R; i++) in[i] = true;
return;
}
pushdown(o);
if(L == R) return;
int M = (L + R) / ;
query(o*, L, M);
query(o*+, M+, R);
} char cmd, _left, _right; int main()
{
//freopen("in.txt", "r", stdin); while(scanf("%c %c%d,%d%c\n", &cmd, &_left, &qL, &qR, &_right) >= )
{
qL <<= ; qR <<= ;
if(_left == '(') qL++; if(_right == ')') qR--;
if(qL > qR && (cmd == 'I' || cmd == 'C')) { setv[] = ; xorv[] = ; continue; }
if(cmd == 'U') { op = ; update(, , maxn, qL, qR); }
else if(cmd == 'I')
{
op = ;
if(qL - >= ) update(, , maxn, , qL-);
if(qR + <= maxn) update(, , maxn, qR+, maxn);
}
else if(cmd == 'D') { op = ; update(, , maxn, qL, qR); }
else if(cmd == 'C')
{
op = ;
if(qL - >= ) update(, , maxn, , qL-);
if(qR + <= maxn) update(, , maxn, qR+, maxn);
op = ;
update(, , maxn, qL, qR);
}
else if(cmd == 'S') { op = ; update(, , maxn, qL, qR); }
}
query(, , maxn);
bool print = false;
int s = -, e;
for(int i = ; i <= maxn; i++)
{
if(in[i])
{
if(s == -) s = i;
e = i;
}
else if(s != -)
{
if(print) printf(" ");
print = true;
printf("%c%d,%d%c", s&?'(':'[', s>>, (e+)>>, e&?')':']');
s = -;
}
} if(!print) puts("empty set"); return ;
}
代码君
POJ 3225 (线段树 区间更新) Help with Intervals的更多相关文章
- POJ 3225 线段树区间更新(两种更新方式)
http://blog.csdn.net/niuox/article/details/9664487 这道题明显是线段树,根据题意可以知道: (用0和1表示是否包含区间,-1表示该区间内既有包含又有不 ...
- poj 3468 线段树区间更新/查询
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...
- hdu 1698+poj 3468 (线段树 区间更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1698 这个题意翻译起来有点猥琐啊,还是和谐一点吧 和涂颜色差不多,区间初始都为1,然后操作都是将x到y改为z,注 ...
- poj 2777 线段树 区间更新+位运算
题意:有一个长板子,分成多段,有两种操作,第一种是C给从a到b那段染一种颜色c,另一种是P询问a到b有多少种不同的颜色.Sample Input2 2 4 板长 颜色数目 询问数目C 1 1 2P ...
- POJ 2528 Mayor's posters (线段树区间更新+离散化)
题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...
- POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)
POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...
- POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询)
POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大 ...
- POJ 2528 Mayor's posters 【区间离散化+线段树区间更新&&查询变形】
任意门:http://poj.org/problem?id=2528 Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total S ...
- 【POJ 2777】 Count Color(线段树区间更新与查询)
[POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4094 ...
随机推荐
- 网页出现scanstyles does nothing in Webkit / Mozilla的解决方法
今天ytkah要验证一些百度服务,那边的客服MM说她用ie浏览器打开网页出现"scanstyles does nothing in Webkit / Mozilla / Opera" ...
- 当你碰到一个网络中有多个PXE Server 肿么办?
今天在用PXE 安装Openstack Compute节点时,郁闷得发现同一网段中还有一个PXE Server,而我的Compute 启动起来总会先找到它,但那个设置不受我控制,子网也不归我管,那个s ...
- POJ 2992 Divisors (求因子个数)
题意:给n和k,求组合C(n,k)的因子个数. 这道题,若一开始先预处理出C[i][j]的大小,再按普通方法枚举2~sqrt(C[i][j])来求解对应的因子个数,会TLE.所以得用别的方法. 在说方 ...
- java 以及 vs 的快捷键
javactrl+shift+y 小写ctrl+shift+x 大写ctrl+shift+f 格式化代码 vsctrl+u 小写ctrl+shift+u 大写ctrl+k+f 格式化代码
- MySQL 5.1参考手册
目录 前言 1. 一般信息 1.1. 关于本手册 1.2. 本手册采用的惯例 1.3. MySQL AB概述 1.4. MySQL数据库管理系统概述 1.4.1. MySQL的历史 1.4.2. My ...
- HTTP协议header标头详解
本文根据RFC2616(HTTP/1.1规范),参考 http://www.w3.org/Protocols/rfc2068/rfc2068 http://www.w3.org/Protocols/r ...
- 简明Vim练级攻略(转)
前言今天看到这篇文章,共鸣点非常多.它把Vim使用分为4个级别,目前我自己是熟练运用前面三级的命令,在培养习惯使用第四级.完全就是我这一年来坚持使用Vim的过程.所以不管怎么我要转载这篇文章.翻译自& ...
- Windows 回调监控 <二>
在之前的文章Windows 回调监控 <一> 总结了关于CreateProcessNotify,CreateProcessNotifyEx和LoadImageNotify一些用法,之后产生 ...
- [RM HA 1] Cloudera CDH5 RM HA功能验证
简介: 最新的Cloudera CDH5.0.0 beta版本已经支持RM的HA, 笔者为此简单验证了RM HA的功能. 后续将继续分析其HA的原理,以及其与社区RM HA的区别. 集群部属与RM f ...
- 数组使用find查询用法
#include "stdafx.h"#include <string>#include <list>#include <algorithm># ...