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

  

  题目大致就是说对一个线段进行操作,然后问集合。
  首先要处理的是开区间和闭区间的表示,把所有数乘以2,开的话+1或-1(根据在左边还是右边而定)。
  然后就是集合的操作,并集的话直接覆盖为1,交集的话T的补集覆盖为0,D得话T覆盖为0,C的话先把T的补集覆盖为0,然后T区间取反,S的话T区间取反就好。
  有两个操作,所以维护两个操作,覆盖和取反。
  这里要注意,取反之后覆盖的话要把取反标记为0。
  另外,覆盖的话可以用-1为没有覆盖过,0为覆盖0,1为覆盖1,。
  也可以用0为没覆盖过,1为覆盖1,然后覆盖0的操作等价于覆盖1,然后取反。(我就是这样做的。)
 
代码如下:
#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 , 线段树+集合。的更多相关文章

  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 1436 Horizontally Visible Segments , 线段树+区间更新。

    Description There is a number of disjoint vertical line segments in the plane. We say that two segme ...

  4. POJ 3225 Help with Intervals(线段树)

    POJ 3225 Help with Intervals 题目链接 集合数字有的为1,没有为0,那么几种操作相应就是置为0或置为1或者翻转,这个随便推推就能够了,然后开闭区间的处理方式就是把区间扩大成 ...

  5. POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)

    POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...

  6. POJ 2528 Mayor's posters(线段树+离散化)

    Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...

  7. POJ 2528 Mayor's posters (线段树)

    题目链接:http://poj.org/problem?id=2528 题目大意:有一个很上的面板, 往上面贴海报, 问最后最多有多少个海报没有被完全覆盖 解题思路:将贴海报倒着想, 对于每一张海报只 ...

  8. POJ 2892 Tunnel Warfare(线段树单点更新区间合并)

    Tunnel Warfare Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 7876   Accepted: 3259 D ...

  9. POJ 2777 Count Color(线段树染色,二进制优化)

    Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 42940   Accepted: 13011 Des ...

随机推荐

  1. SqlMapClient ,SqlExecutor 和SqlMapClientTemplate 的区别?

    SqlMapClient SqlExecutor SqlMapClientTemplate

  2. 在CDockablePane中嵌入对话框

    CDockablePane类可以用来创建停靠栏.可以将其他控件集成到CDockablePane的派生类中.下文描述如何将对话框集成到CDockablePane中. a)      创建单文档应用程序: ...

  3. CodeForces 383D Antimatter

    线性DP. dp[i][j]表示以第i个数字为结尾的,字串和为j的有几种. #include<cstdio> #include<cstring> #include<cma ...

  4. java项目(java project)如何导入jar包的解决方案列表

    右键项目-properties-java build path(左侧菜单)-选择libraries 有两种方式,导入jar包实际上就是建立一种链接,并不是copy式的导入 一.导入外部包,add ex ...

  5. Apache无法启动提示the requested operation has failed

    主要参考这篇 http://apps.hi.baidu.com/share/detail/15868128 但还是遇到一些问题,记录如下: 1. 配置完成后,restart apache,出现 the ...

  6. 当浏览器窗体改变时,div跟着变动方法

    $(function(){ resizeU(); $(window).resize(resizeU); }); function resizeU() { var divkuangH = $(windo ...

  7. maven 教程一 入门

    摘要: (1)maven是项目管理工具,类似makefile.主要的生命阶段有 validate:验证工程是否正确,所有需要的资源是否可用.  compile:编译项目的源代码.    test:使用 ...

  8. Sphinx配置过程

    http://www.oschina.net/question/84274_11938 http://www.ibm.com/developerworks/library/os-php-sphinxs ...

  9. Angular中ngModel的$render的详解

    在我开始着手ngModel的领域时候,有一个问题很令我纠结,那就是$render()到底是做什么的呢?查了很多资料都只是简单的描述一下,这就令我很纠结了,终于在一个阳光明媚的晚上,我终于解决了这个大问 ...

  10. Android NDK 下的宽字符编码转换及icu库的使用(转)

    原贴http://topic.csdn.net/u/20101022/16/1b2e0cec-b9d2-42ea-8d9c-4f1bb8320a54.html?r=70149216 ,看过并动手实现, ...