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. php5权限控制修饰符

    1.public:public表明该数据成员.成员函数是对所有用户开放的,所有用户都可以直接进行调用 2.private:private表示私有,私有的意思就是除了class自己之外,任何人都不可以直 ...

  2. tree 核心命令参数

    常用参数: -a  显示所有文件 包括隐藏文件 -d 只显示目录 -f 显示每个文件的全路径 -i 不显示树枝 常与-f一起搭配 -L 显示的层数 -F 区分哪个文件是目录 [root@ftp:/va ...

  3. OpenStack 与 大数据的融合

        此处是hadoop 2.7.2以前 Hadoop 预留的一个 HDFS 文件系统的接口. 可以通过修改这里 将数据源的读取改为 Swift. 也可以通过修改 MR 源码 将数据抽取部分变换成 ...

  4. spring data redis jackson 配置,工具类

    spring data redis 序列化有jdk .jackson.string 等几种类型,自带的jackson不熟悉怎么使用,于是用string类型序列化,把对象先用工具类转成string,代码 ...

  5. bzoj1211: [HNOI2004]树的计数(prufer序列+组合数学)

    1211: [HNOI2004]树的计数 题目:传送门 题解: 今天刚学prufer序列,先打几道简单题 首先我们知道prufer序列和一颗无根树是一一对应的,那么对于任意一个节点,假设这个节点的度数 ...

  6. Python 序列化处理

    序列化 文件为dump 字符串为dumps dumps()方法返回一个str,内容就是标准的JSON loads()方法将其还原 在程序运行的过程中,所有的变量都是在内存 d = dict(name= ...

  7. 【转】Android ClearEditText:输入用户名、密码错误时整体删除及输入为空时候晃动提示

    1 package com.lixu.clearedittext; 2 3 4 import android.app.Activity; 5 import android.os.Bundle; 6 i ...

  8. Metasploit的三种启动方式

    不多说,直接上干货! 注意:博主我用的是Kali linux 2016.2(Rolling).  msfcli 的启动 root@kali:~# msfcli -h bash: msfcli: 未找到 ...

  9. ip反查域名的详细信息(多种方法)

    不多说,直接上干货! 至于这里怎FQ,很简单,请见我下面的博客! kali 2.0安装 lantern(成功FQ) shadowsocks(简称SSFQ软件)步骤详解 FQ软件lantern-inst ...

  10. [转]A reference to a higher version or incompatible assembly cannot be added to the project

    If you face this error message while adding a reference to your project in Visual Studio try the fol ...