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. 函数求值一<找规律>

    函数求值 题意: 定义函数g(n)为n最大的奇数因子.求f(n)=g(1)+g(2)+g(3)+-+g(n).1<=n<=10^8; 思路: 首先明白暴力没法过.问题是如何求解,二分.知道 ...

  2. UITextField和一个UILabel绑定 浅析

    转载自:http://fengdeng.github.io/blog/2016/01/22/rxswift-dao-di-%5B%3F%5D-ge-uitextfieldshi-ru-he-he-%5 ...

  3. 在win7 64bit系统安装QC软件

    当本机系统不再QC软件支持的系统上,可以在setup右键选择兼容性选择能支持安装的系统, 在JBOSS页面,选择该服务器,用户名输入本机的用户名和密码,如果没有配置域输入计算机名. 如果没有装IIS, ...

  4. a:link visited hover active

    CSS中a:link.a:visited.a:hover.a:active的用法:建议:尽可能的手写代码,可以有效的提高学习效率和深度.在网页设计中,设计美观的超链接效果可以增强网站的用户体验,可能会 ...

  5. SQL Server 自定义快捷键

    SQL Server程序员经常要在SSMS(SQL Server Management Studio)或查询分析器(2000以前)中编写T-SQL代码.以下几个技巧,可以提升工作效率. 以下说明以SS ...

  6. 《CSS设计指南》阅读笔记

    一.HTML实体 HTML实体常用于生成那些键盘上没有的印刷字符.以一个和号(&)开头,一个分号(:)结尾,二者之间是表示实体的字符串. 如:“左引号(")     ”右引号(&qu ...

  7. Linux学习 -- 文件系统管理

    1 分区和文件系统 分区类型 主分区:<= 4个 扩展分区:只能有一个,也算主分区的一种   不能存储数据和格式化,只能用来包含逻辑分区 逻辑分区:扩展分区中划分的   IDE--最多59个   ...

  8. storm第一篇--概念,例子,参数优化

    1 概念 目前最新的0.8.0版本里面 worker -> 进程.一个worker只能执行同一个spout/bolt的task,一个worker里面可以有多个executor. executor ...

  9. iptables详解--转

    出处:http://yijiu.blog.51cto.com/433846/1356254 iptables详解 基本概念: 1.防火墙工作在主机边缘:对于进出本网络或者本主机的数据报文,根据事先设定 ...

  10. idx_rebuild_diff_idx_l.sql

    1. set echo on feedback on set timing on set time on set pagesize 1000 set linesize 150 spool 02_do_ ...