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

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

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

另外,如果因为可能要更新多次,但最终查询只需要一次,所以没有写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. AESEncrypter加密算法代码示例

    package testJava.java; import java.security.SecureRandom; import java.util.Base64; import javax.cryp ...

  2. FM算法

    1.FM背景 在计算广告中,CTR预估(click-through rate)是非常重要的一个环节,因为DSP后面的出价要依赖于CTR预估的结果.在前面的相关博文中,我们已经提到了CTR中相关特征工程 ...

  3. POJ 1939

    #include<iostream> #include<iomanip> #define MAXN 10000 using namespace std; ]; int main ...

  4. Codeforces Round #263 (Div. 2) A B C

    题目链接 A. Appleman and Easy Task time limit per test:2 secondsmemory limit per test:256 megabytesinput ...

  5. UVA 10574 - Counting Rectangles 计数

    Given n points on the XY plane, count how many regular rectangles are formed. A rectangle is regular ...

  6. unity HideInInspector 默认值 坑 记录 bug

    1:   如果  一个public字段 刚开始有默认值,然后你你觉得这个值不应该给别人看设置为HideInInspector 后,你再在代码里面调整这个默认属性的值,这个时候代码里面调整的值无效.   ...

  7. 屏幕实战效果解析:IPS/TFT/AMOLED/SLCD

    现在手机市场上,智能手机种类繁多,手机屏幕材质也是五花八门.对于一般消费者来说,一款手机是否值得购买,除了关心它的硬件参数以外,更重要的一点就是看它的屏幕.除了屏幕尺寸以外,影响着大家对该手机的第一感 ...

  8. Box2d学习

    Box2d 学习 . Testbed 项目: Testbed 是 Box2d 源码里包含的一个例子程序.Testbed 封装了界面显示.游戏循环等部分的代码.添加新的例子的时候,只需要关注与 Box ...

  9. Centos 用户组管理

    #组帐号管理 linux 组管理 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--= 1.组的分类 私用组:只能包含一个用 ...

  10. Java:日历类、日期类、数学类、运行时类、随机类、系统类

    一:Calendar类 java.util 抽象类Calendar   1.static Calendar getInstance()使用默认时区和语言环境获得一个日历. 2. int get(int ...