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. vue项目,封装api并使用

    封装api index.js let uploadBase = '' if(process.env.NODE_ENV === 'production'){ uploadBase = 'https:// ...

  2. String值传递剖析

    转载自 http://www.iteye.com/topic/412531 提要:本文从实现原理的角度上阐述和剖析了:在Java语言中,以String作为类型的变量在作为方法参数时所表现出的“非对象” ...

  3. [arc076f]Exhausted? - 贪心

    题意: 给你m个椅子可以坐人,初始坐标为正整数1~m,有n个人,每个人希望坐的位置$\leq L_i$或者$\geq R_i$,可以添加若干个椅子在任意的实数位置,求最少要添加多少椅子使得所有人都有位 ...

  4. 微信小程序 刷新页面

    一 , 当前页面刷新 第一种方式: //pages 获取到当前页码数 然后执行当前页的onLoad const pages = getCurrentPages() ] perpage.onLoad() ...

  5. POJ-3660 Cow Contest Floyd传递闭包的应用

    题目链接:https://cn.vjudge.net/problem/POJ-3660 题意 有n头牛,每头牛都有一定的能力值,能力值高的牛一定可以打败能力值低的牛 现给出几头牛的能力值相对高低 问在 ...

  6. CF17E Palisection(manacher)

    题意 给出一个长度为N的字符串S,问S中有多少个回文子串对(i,j)使得i,j在S中的位置相交?(N<=2*106) 题解 #include<iostream> #include&l ...

  7. C语言实现简化的正则表达式

    语法: 正则表达式和待匹配字符串都是一行 "^" 标记正则表达式的开始 "$" 标记正则表达式的结束 "*" 匹配前面的子表达式零次或多次 ...

  8. HTTP——学习笔记(7)

    HTTP中的认证机制 什么是认证机制?: 服务器需要知道客户端是谁. 怎样知道客户端身份?: 核对“登录者本人才知道的信息” 密码:只有本人才会知道的字符串信息 动态令牌:仅限本人持有的设备内显示的一 ...

  9. 传纸条 NOIP2008 洛谷1006 二维dp

    二维dp 扯淡 一道比较基本的入门难度的二维dp,类似于那道方格取数,不过走过一次的点下次不能再走(看提交记录里面好像走过一次的加一次a[i][j]的也AC了,,),我记得当年那道方格取数死活听不懂, ...

  10. EEPlat PaaS中的多租户数据隔离模式

    EEPlat PaaS支持三种租户的数据隔离技术:Sparce Column.tenantId字段隔离.每一个租户独立数据库. 1)Sparce Column,和Salesforce Appforce ...