(中等) POJ 3225 Help with Intervals , 线段树+集合。
Description
LogLoader, Inc. is a company specialized in providing products for analyzing logs. While Ikki is working on graduation design, he is also engaged in an internship at LogLoader. Among his tasks, one is to write a module for manipulating time intervals, which have confused him a lot. Now he badly needs your help.
In discrete mathematics, you have studied several basic set operations, namely union, intersection, relative complementation and symmetric difference, which naturally apply to the specialization of sets as intervals.. For your quick reference they are summarized in the table below:
Operation Notation Definition
Union A ∪ B {x : x ∈ A or x ∈ B} Intersection A ∩ B {x : x ∈ A and x ∈ B} Relative complementation A − B {x : x ∈ A but x ∉ B} Symmetric difference A ⊕ B (A − B) ∪ (B − A)
Ikki has abstracted the interval operations emerging from his job as a tiny programming language. He wants you to implement an interpreter for him. The language maintains a set S, which starts out empty and is modified as specified by the following commands:
| Command | Semantics |
|---|---|
U T |
S ← S ∪ T |
I T |
S ← S ∩ T |
D T |
S ← S − T |
C T |
S ← T − S |
S T |
S ← S ⊕ T |
#include<iostream>
#include<cstdio>
#include<cstring> #define lson L,M,po*2
#define rson M+1,R,po*2+1 using namespace std; const int N=*; bool COL[*]={};
bool XOR[*]={};
bool vis[]={};
bool have=; void pushDown(int po)
{
if(COL[po])
{
COL[po*]=COL[po*+]=COL[po];
COL[po]=;
XOR[po*]=XOR[po*+]=; // don't forget!!!
} if(XOR[po])
{
XOR[po*]=!XOR[po*];
XOR[po*+]=!XOR[po*+];
XOR[po]=;
}
} void updateC(int ul,int ur,bool type,int L,int R,int po)
{
if(ul>ur)
return; if(ul<=L&&ur>=R)
{
XOR[po]=;
COL[po]=type; return;
} pushDown(po); int M=(L+R)/; if(ul<=M)
updateC(ul,ur,type,lson);
if(ur>M)
updateC(ul,ur,type,rson);
} void updateX(int ul,int ur,int L,int R,int po)
{
if(ul>ur)
return; if(ul<=L&&ur>=R)
{
XOR[po]=!XOR[po]; return;
} pushDown(po); int M=(L+R)/; if(ul<=M)
updateX(ul,ur,lson);
if(ur>M)
updateX(ul,ur,rson);
} void query(int L,int R,int po)
{
if(L==R)
{
vis[L]=COL[po]^XOR[po]; if(vis[L])
have=; return;
} pushDown(po); int M=(L+R)/; query(lson);
query(rson);
} int main()
{
char C;
char t1,t2;
int a,b;
int x,y; while(cin>>C)
{
scanf(" %c%d,",&t1,&a);
scanf("%d%c",&b,&t2); a*=;
b*=; if(t1=='(')
++a;
if(t2==')')
--b; switch(C)
{
case 'U':
updateC(a,b,,,N,);
break; case 'I':
updateC(,a-,,,N,);
updateX(,a-,,N,);
updateC(b+,N,,,N,);
updateX(b+,N,,N,);
break; case 'D':
updateC(a,b,,,N,);
updateX(a,b,,N,);
break; case 'C':
updateC(,a-,,,N,);
updateX(,a-,,N,);
updateC(b+,N,,,N,);
updateX(b+,N,,N,);
updateX(a,b,,N,);
break; case 'S':
updateX(a,b,,N,);
break; }
} query(,N,); if(!have)
{
printf("empty set\n");
return ;
} bool has=;
for(int i=;i<=N+;++i)
{
if(vis[i])
{
if(!has)
{
has=;
if(i%)
printf("(%d,",(i-)/);
else
printf("[%d,",i/);
}
}
else
{
if(has)
{
has=;
if((i-)%)
printf("%d) ",i/);
else
printf("%d] ",(i-)/);
}
}
} return ;
}
(中等) 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 1436 Horizontally Visible Segments , 线段树+区间更新。
Description There is a number of disjoint vertical line segments in the plane. We say that two segme ...
- POJ 3225 Help with Intervals(线段树)
POJ 3225 Help with Intervals 题目链接 集合数字有的为1,没有为0,那么几种操作相应就是置为0或置为1或者翻转,这个随便推推就能够了,然后开闭区间的处理方式就是把区间扩大成 ...
- 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 ...
随机推荐
- 关于tag,viewWithTag
iOS SDK内置了一套搜寻机制,可通过tag来查找子视图. **苹果公司很少给子视图设置tag.笔者所知范围的唯一例外出现在UIAlertView中,该类会给按钮分别设置值为1.2的标签 viewW ...
- jquery 功能强大的下拉菜单
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org ...
- sqlserver2008行锁
select * from tablename WITH (UPDLOCK) where Id=#value#
- JS-DOM操作应用
父级.appendChild(子节点) 父级.insertBefore(子节点,在谁之前) <title>无标题文档</title> <script> window ...
- 用cas来实现php的单点登陆
最近项目中需要做单点登录,客户端包含Java.ruby和PHP,java有几个应用程序,php是discuz+supesite+ucenter,配置步骤如下: 1.cas服务端:下载地址:http:/ ...
- DataBinding注意事项Error parsing XML: duplicate attribute以及如何在listview中使用DataBinding
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- Eclipse中代码提示框的背景色修改
Preferences->General->Appearance->Colors and Fonts 修改Basic中的Content Assist backgroud color[ ...
- iOSFMDB和CoreData
转发:http://wenku.baidu.com/link?url=LSPSZSPxN4pVwWNwqEXSoY0-jlnXq-_14C7qV1FV9_gFIMPjdKlXrG4Nrh_08EZS1 ...
- 解开神秘面纱之“AngualrJS 中指令相关的嵌入作用域和模板作用域”
原文:https://www.airpair.com/angularjs/posts/transclusion-template-scope-in-angular-directives#r1 原标题: ...
- ExtJS4.1自带API打不开的问题解决
在ext官网个下载的最新版本的extjs,本来想看看里面的docs文档的,结果却发现打不开,总是转个不停,于是就打开index.html的源码,看到引入ext的js文件的时候,看到引入的是ext.js ...