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

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

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

另外,如果因为可能要更新多次,但最终查询只需要一次,所以没有写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. ASP.NET MVC中几个运用技巧

    1. Razor Helpers 的运用:例如,定义好 ViewBag.Message = "Welcome to ASP.NET MVC!";我要在界面上显示"Welc ...

  2. 全栈式JavaScript

    如今,在创建一个Web应用的过程中,你需要做出许多架构方面的决策.当然,你会希望做的每一个决定都是正确的:你想要使用能够快速开发的技术,支持持续的迭代,最高的工作效率,迅速,健壮性强.你想要精益求精并 ...

  3. HDOJ 2069 Coin Change(母函数)

    Coin Change Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. HDU2295 Radar (DLX)

    下面的代码99%参考了这个网站http://www.cnblogs.com/183zyz/archive/2011/08/07/2130193.html 人生的第一道DLX肯定是需要作一些参考的啦. ...

  5. HDU 4825 Xor Sum(二进制的字典树,数组模拟)

    题目 //居然可以用字典树...//用cin,cout等输入输出会超时 //这是从别处复制来的 #include<cstdio> #include<algorithm> #in ...

  6. 2013 ACM/ICPC Asia Regional Changsha Online G Goldbach

    比赛的时候,被题目误导了,题目最后说结果可能很大,要取模,那时就想直接求会TLE的!!! 赛后才知道,坑啊………… 代码如下: #include<iostream> #include< ...

  7. poj 2311 Cutting Game 博弈论

    思路:求SG函数!! 代码如下: #include<iostream> #include<cstdio> #include<cmath> #include<c ...

  8. C# 实现抓取网站页面内容

    抓取新浪网的新闻栏目,如图所示: 使用 谷歌浏览器的查看源代码: 通过分析得知,我们所要找的内容在以下两个标签之间: <!-- publish_helper name='要闻-新闻' p_id= ...

  9. Combination Sum III

    https://leetcode.com/problems/combination-sum-iii/ Find all possible combinations of k numbers that ...

  10. iOS开发--线程通信

    线程间的通信主要用于主线程与子线程的,也有用于子线程与子线程的 介绍下面几种通信方式 1.利用GCD方式(推荐) - (void)touchesBegan:(NSSet<UITouch *> ...