这道题搞了好久,其实坑点挺多。。

网上找了许多题解,发现思路其实都差不多,所以就不在重复了。

推荐一篇比较好的题解,请戳这

另外,如果因为可能要更新多次,但最终查询只需要一次,所以没有写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的更多相关文章

  1. POJ 3225 线段树区间更新(两种更新方式)

    http://blog.csdn.net/niuox/article/details/9664487 这道题明显是线段树,根据题意可以知道: (用0和1表示是否包含区间,-1表示该区间内既有包含又有不 ...

  2. poj 3468 线段树区间更新/查询

    Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...

  3. hdu 1698+poj 3468 (线段树 区间更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=1698 这个题意翻译起来有点猥琐啊,还是和谐一点吧 和涂颜色差不多,区间初始都为1,然后操作都是将x到y改为z,注 ...

  4. poj 2777 线段树 区间更新+位运算

    题意:有一个长板子,分成多段,有两种操作,第一种是C给从a到b那段染一种颜色c,另一种是P询问a到b有多少种不同的颜色.Sample Input2 2 4  板长 颜色数目 询问数目C 1 1 2P ...

  5. POJ 2528 Mayor's posters (线段树区间更新+离散化)

    题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...

  6. POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)

    POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...

  7. POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询)

    POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大 ...

  8. POJ 2528 Mayor's posters 【区间离散化+线段树区间更新&&查询变形】

    任意门:http://poj.org/problem?id=2528 Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  9. 【POJ 2777】 Count Color(线段树区间更新与查询)

    [POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4094 ...

随机推荐

  1. Yarn的服务库和事件库使用方法

    事件类型定义: package org.apache.hadoop.event; public enum JobEventType { JOB_KILL, JOB_INIT, JOB_START } ...

  2. AJAX实现仿Google Suggest效果

    修复了一些细节代码(支持持续按键事件) *项目名称:AJAX实现类Google Suggest效果*作者:草履虫(也就是蓝色的ecma)*联系:caolvchong@gmail.com*时间:2007 ...

  3. HDOJ 1220 Cube

    CubeTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  4. 谈谈arm下的函数栈

    引言 这篇文章简要说说函数是怎么传入参数的,我们都知道,当一个函数调用使用少量参数(ARM上是少于等于4个)时,参数是通过寄存器进行传值(ARM上是通过r0,r1,r2,r3),而当参数多于4个时,会 ...

  5. Unity3D战争迷雾效果

    原地址:http://liweizhaolili.blog.163.com/blog/static/16230744201431835652233/ 最近一直都在做Flash相关的东西,很久没有空搞U ...

  6. POJ 2004 Mix and Build (预处理+dfs)

    题意: 给N个字符串,要求出一个序列,在该序列中,后一个串,是由前一个串加一个字母后得来的(顺序可以改动). 问最多能组成多长的序列.思路:将给的字符串排序,再对所有的字符串按长度从小到大排序,若长度 ...

  7. D&F学数据结构系列——B树(B-树和B+树)介绍

    B树 定义:一棵B树T是具有如下性质的有根树: 1)每个节点X有以下域: a)n[x],当前存储在X节点中的关键字数, b)n[x]个关键字本身,以非降序存放,因此key1[x]<=key2[x ...

  8. 【BZOJ1878】[SDOI2009]HH的项链 离线BIT

    1878: [SDOI2009]HH的项链 Description HH有一串由各种漂亮的贝壳组成的项链.HH相信不同的贝壳会带来好运,所以每次散步 完后,他都会随意取出一段贝壳,思考它们所表达的含义 ...

  9. poj3415 Common Substrings(后缀数组,单调栈 | 后缀自动机)

    [题目链接] http://poj.org/problem?id=3415 [题意] A与B长度至少为k的公共子串个数. [思路] 基本思想是将AB各个后缀的lcp-k+1的值求和.首先将两个字符串拼 ...

  10. C编译器剖析PDF文档及UCC编译器162.3

    http://blog.csdn.net/sheisc/article/details/42387857 http://blog.csdn.net/sheisc/article/details/455 ...