POJ 3225 Help with Intervals(线段树)
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(线段树)的更多相关文章
- poj 3225 Help with Intervals(线段树,区间更新)
Help with Intervals Time Limit: 6000MS Memory Limit: 131072K Total Submissions: 12474 Accepted: ...
- POJ 3225 Help with Intervals --线段树区间操作
题意:给你一些区间操作,让你输出最后得出的区间. 解法:区间操作的经典题,借鉴了网上的倍增算法,每次将区间乘以2,然后根据区间开闭情况做微调,这样可以有效处理开闭区间问题. 线段树维护两个值: cov ...
- (中等) POJ 3225 Help with Intervals , 线段树+集合。
Description LogLoader, Inc. is a company specialized in providing products for analyzing logs. While ...
- POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)
POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...
- POJ 2528 Mayor's posters(线段树+离散化)
Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...
- POJ 2528 Mayor's posters (线段树)
题目链接:http://poj.org/problem?id=2528 题目大意:有一个很上的面板, 往上面贴海报, 问最后最多有多少个海报没有被完全覆盖 解题思路:将贴海报倒着想, 对于每一张海报只 ...
- POJ 2892 Tunnel Warfare(线段树单点更新区间合并)
Tunnel Warfare Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 7876 Accepted: 3259 D ...
- POJ 2777 Count Color(线段树染色,二进制优化)
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 42940 Accepted: 13011 Des ...
- Codeforces Gym 100231B Intervals 线段树+二分+贪心
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...
随机推荐
- CDR X6低价还能持续多久?官方回应18年元旦过后要涨价
目前,CDR X6特价活动,从双十二的到18年的元旦,火热程度一直屡刷新高,究其原因,其实不是大家不需要,只是这个平面设计软件价格实在太高(CDR X8/8200:CDR 2017/9500一套),尤 ...
- 路飞学城Python-Day7(practise)
# 1.编码问题# i.请说明python2与python3中的默认编码是什么?# python2中的默认编码是ASCII码,只能识别英文等其他字符# python3中的默认编码是utf-8# ii. ...
- KMP笔记
KMP #include<iostream> #include<cstring> #include<cstdio> #include<cmath> us ...
- 关于JavaScript中this的指向,你知晓几分?请速来围观!
---恢复内容开始--- 一.this是什么东东? this是指包含它的函数作为方法被调用时所属的对象.这句话理解起来跟卵一样看不懂,但是如果你把它拆分开来变成这三句话后就好理解一点了. 1.包含它的 ...
- Linux Shell脚本编程-信号捕获
bash编程的信号捕获: kill -l 显示当前系统可用信号(trap -l) 获取帮助:man 7 single 常用信号: 1) SIGHUP 无须重启进程而让其重读配置文件 2) SI ...
- 一线 | 中国联通宣布首批5G手机到位
腾讯<一线> 作者郭晓峰 据中国联通相关人士今日透露,中国联通用于 5G 友好体验的首批合作 5G 手机全部到位.有 12 个品牌共 15 款 5G 手机及 5G CPE,包括.华为. O ...
- 不要在.h文件中定义变量
今天在头文件.h中初始化了一个数组和函数,在编译的时候提示这个数组和函数重新定义了,检查后发现,犯了一个致命的错误,在头文件中定义变量... 以下引用别人的一篇说明,警示自己. C语言作为一种结构化的 ...
- 【BZOJ 1269】 [AHOI2006]文本编辑器editor
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] /* [move k] 指令.直接 把pos改成k.表示改变光标位置 [insert n s],在pos后面插入一个长度为n的字符串 ...
- Linux 设备驱动之 UIO 机制(基本概念)
一个设备驱动的主要任务有两个: 1. 存取设备的内存 2. 处理设备产生的中断 对于第一个任务.UIO 核心实现了mmap()能够处理物理内存(physical memory),逻辑内存(logica ...
- TCO14 1B L3: EagleInZoo, dp,tree
题目:http://community.topcoder.com/stat?c=problem_statement&pm=13117&rd=15950 看到树,又是与节点有关,通常是d ...