(中等) 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 ...
随机推荐
- xntp的配置
ntpdate以一种非常粗暴的方式一次性完成设置时钟.由于实时时钟飘移,你需要周期性的矫正.基本上可以通过设置一个cron例行任务来运行ntpdate,但是你的机器从此就不能是ntp服务器了. 相反, ...
- 字段为空sql语句,设置当前模式
delete from t_corpinfo where CORPID='' and CORPNAME='' 该命令是删除字段为空的记录 SET CURRENT SCHEMA DB2INST1;
- Python -- 文档测试
Python内置的“文档测试”(doctest)模块可以直接提取注释中的代码并执行测试. 例子: # mydict2.py class Dict(dict): ''' Simple dict but ...
- 转:selenium webdriver 执行javascript代码
在用selenium webdriver 编写web页面的自动化测试代码时,可能需要执行一些javascript代码,selenium本身就支持执行js,我们在代码中import org.openqa ...
- 使用libvirt做适配的kvm虚拟机window server 2008 磁盘性能的提升
实验室自己做了一个iaas的项目,当时是为了更方面的在kvm和xen下进行迁移,所以选择了libvirt作为适配层. 昨天简单的测试一了一下我们跟qingcloud的性能对比.我们的linux主机性能 ...
- ubuntu 解压 windows 生成的 zip 文件乱码问题
在windows上压缩的文件,是以系统默认编码中文来压缩文件.由于zip文件中没有声明其编码,所以linux上的unzip一般以默认编码解压,中文文件名会出现乱码. 有两种方式解决问题:(建议采用方法 ...
- 第13章 Swing程序设计----常用事件监听器
组件本身并不带有任何功能.这时需要为这些组件添加特定事件监听器. Swing中常用的两个事件监听器,即动作事件监听器和焦点事件监听器.
- cookies和session的优缺点
具体来说cookie机制采用的是在客户端保持状态的方案,而session机制采用的是在服务器端保持状态的方案. Cookie的优缺点: 优点:极高的扩展性和可用性通过良好的编程,控制保存在cookie ...
- JavaBean-- 设置和取得属性
<jsp:setProperty>标签一共有4种使用方法: 自动匹配:<jsp:setProperty name="实例化对象的名称(id)" property= ...
- Windows查看端口被哪个进程占用
命令 查看PID: netstat -ano|findstr 端口号 查看进程名称: tasklist|findstr PID 结束进程: taskkill -F -PID PID号 配图详解: 1. ...