POJ 3225 Help with Intervals

题目链接

集合数字有的为1,没有为0,那么几种操作相应就是置为0或置为1或者翻转,这个随便推推就能够了,然后开闭区间的处理方式就是把区间扩大成两倍,偶数存点,奇数存线段就可以

代码:

#include <cstdio>
#include <cstring> #define lson(x) ((x<<1)+1)
#define rson(x) ((x<<1)+2) const int N = 65536 * 2; struct Node {
int l, r, flip, setv;
} node[N * 4]; int to[N]; void build(int l, int r, int x = 0) {
node[x].l = l; node[x].r = r;
node[x].flip = 0; node[x].setv = -1;
if (l == r) {
to[l] = x;
return;
}
int mid = (l + r) / 2;
build(l, mid, lson(x));
build(mid + 1, r, rson(x));
} void pushdown(int x) {
if (node[x].setv != -1) {
node[lson(x)].setv = node[rson(x)].setv = node[x].setv;
node[lson(x)].flip = node[rson(x)].flip = 0;
node[x].setv = -1;
}
if (node[x].flip) {
node[lson(x)].flip ^= 1;
node[rson(x)].flip ^= 1;
node[x].flip = 0;
}
} void add(int l, int r, int v, int x = 0) {
if (l > r) return;
if (node[x].l >= l && node[x].r <= r) {
if (v != -1) {
node[x].setv = v;
node[x].flip = 0;
} else
node[x].flip ^= 1;
return;
}
pushdown(x);
int mid = (node[x].l + node[x].r) / 2;
if (l <= mid) add(l, r, v, lson(x));
if (r > mid) add(l, r, v, rson(x));
} void query(int x = 0) {
if (node[x].l == node[x].r) {
if (node[x].setv == -1) node[x].setv = 0;
return;
}
pushdown(x);
int mid = (node[x].l + node[x].r) / 2;
query(lson(x));
query(rson(x));
} char c, a, b;
int l, r; int main() {
build(0, N - 1);
while (~scanf("%c %c%d,%d%c\n", &c, &a, &l, &r, &b)) {
l = l * 2 + (a == '(');
r = r * 2 - (b == ')');
if (c == 'U') add(l, r, 1);
if (c == 'I' || c == 'C') {
add(0, l - 1, 0);
add(r + 1, N - 1, 0);
if (c == 'C') add(l, r, -1);
}
if (c == 'D') add(l, r, 0);
if (c == 'S') add(l, r, -1);
}
query();
int pre = 0, flag = 0, bo = 0;
for (int i = 0; i < N; i++) {
int id = to[i];
int tmp = (node[id].setv^node[id].flip);
if (!tmp && flag) {
if (bo) printf(" ");
else bo = 1;
if (pre % 2) printf("(");
else printf("[");
printf("%d,%d", pre / 2, i / 2);
if (i % 2 == 0) printf(")");
else printf("]");
flag = 0;
} else if (tmp && !flag) {
pre = i;
flag = 1;
}
}
if (bo == 0) printf("empty set");
printf("\n");
return 0;
}

POJ 3225 Help with Intervals(线段树)的更多相关文章

  1. poj 3225 Help with Intervals(线段树,区间更新)

    Help with Intervals Time Limit: 6000MS   Memory Limit: 131072K Total Submissions: 12474   Accepted:  ...

  2. POJ 3225 Help with Intervals --线段树区间操作

    题意:给你一些区间操作,让你输出最后得出的区间. 解法:区间操作的经典题,借鉴了网上的倍增算法,每次将区间乘以2,然后根据区间开闭情况做微调,这样可以有效处理开闭区间问题. 线段树维护两个值: cov ...

  3. (中等) POJ 3225 Help with Intervals , 线段树+集合。

    Description LogLoader, Inc. is a company specialized in providing products for analyzing logs. While ...

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

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

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

    Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...

  6. POJ 2528 Mayor's posters (线段树)

    题目链接:http://poj.org/problem?id=2528 题目大意:有一个很上的面板, 往上面贴海报, 问最后最多有多少个海报没有被完全覆盖 解题思路:将贴海报倒着想, 对于每一张海报只 ...

  7. POJ 2892 Tunnel Warfare(线段树单点更新区间合并)

    Tunnel Warfare Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 7876   Accepted: 3259 D ...

  8. POJ 2777 Count Color(线段树染色,二进制优化)

    Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 42940   Accepted: 13011 Des ...

  9. Codeforces Gym 100231B Intervals 线段树+二分+贪心

    Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...

随机推荐

  1. IIS支持10万个同时请求的设置

    1. 调整IIS 7应用程序池队列长度 由原来的默认1000改为65535. IIS Manager > ApplicationPools > Advanced Settings Queu ...

  2. Comparator 与 Comparable

    转载自 http://www.cnblogs.com/sunflower627/p/3158042.html 1. Comparator 和 Comparable 相同的地方 他们都是java的一个接 ...

  3. [arc067f]yakiniku restaurants

    题意: n家饭店,m张餐票,第i家和第i+1家饭店之间的距离是$A_i$,在第i家饭店用掉第j张餐票会获得$B_{i,j}$的好感度,但是从饭店i走到饭店j会有$dis_{i,j}$的代价,可以从任意 ...

  4. java compare 时间排序

    所有数据存进resultList中 Collections.sort(resultList, new Comparator<HashMap<String, Object>>() ...

  5. Java Bean 简单介绍及其应用

    Bean的中文含义是"豆子",顾名思义JavaBean是一段Java小程序.JavaBean实际上是指一种特殊的Java类.它通经常使用来实现一些比較经常使用的简单功能.并能够非常 ...

  6. 1.Swift教程翻译系列——关于Swift

    英文版PDF下载地址http://download.csdn.net/detail/tsingheng/7480427 我本来是做JAVA的.可是有一颗折腾的心,苹果公布Swift以后就下载了苹果的开 ...

  7. 28.STL常用算法

    #include <algorithm> 算法 常用版本 描述 返回Type std::find() find(_InIt _Fisrt,_InIt _Last, _Ty& _Va ...

  8. Tomcat下没有编译后的class文件

    输出的路径是否正确: Default output folder: 如果tomcat下还没有classes文件则没有编译好 需要重新引入jar包, clean工程,并重新部署项目. 这样就会在tomc ...

  9. AES简单加密解密的方法实现

    package com.mstf.aes; import java.io.UnsupportedEncodingException; import java.security.InvalidKeyEx ...

  10. AngularJS 导航栏动态添加.active

    在传统jQuery中,实现导航栏动态添加.active类的思路比较简单,就是当点击的时候,清除其他.active,然后给当前类加上.active. 但是在AngularJS中,就不能再采用这种jQue ...