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. opencv---cvor

    void cvXor计算两个数组中的每个元素的按位异或. void cvXor (const CvArr* src1, const CvArr* src2, CvArr* dst, const CvA ...

  2. cocos2d-x 3.x 橡皮擦功能

    1.HelloWorldScene.h cocos2d::DrawNode* _eraser; cocos2d::RenderTexture*_renderTexture; 2.HelloWorldS ...

  3. 河南多校大一训练赛 E 开餐馆

    题目链接:http://acm.hust.edu.cn/vjudge/contest/125004#problem/E 密码:acm Description 北大信息学院的同学小明毕业之后打算创业开餐 ...

  4. UIView 视图切换

    UIView之间常用视图之间切换方式 转载自:http://www.jianshu.com/p/0d53f9402c07 在平时编写代码的过程中,页面之间的跳转可以说就和MVC模式一样是开发必须的.但 ...

  5. CALayer --> UIView

    一.CALayer和UIView的关系 UIView显示在屏幕上归功于CALayer 可以说:UIView依赖CALayer,又高于CALayer 通过调用drawRect方法来渲染自身的内容,调节C ...

  6. codeforces 665B Shopping

    暴力 #include<cstdio> #include<cstring> #include<cmath> #include<vector> #incl ...

  7. ActionBarSherlock,SlidingMenu

    转自:http://www.chenwg.com/android/actionbarsherlock%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B.html Android3 ...

  8. Halcon相关

      1.Halcon的自我描述 Program Logic Ø Each program consists of a sequence of HALCON operators Ø The progra ...

  9. android4.0 的图库Gallery2代码分析(一)

    最近迫于生存压力,不得不给人兼职打工.故在博文中加了个求点击的链接.麻烦有时间的博友们帮我点击一下.没时间的不用勉强啊.不过请放心,我是做技术的,肯定链接没病毒,就是我打工的淘宝店铺.嘻嘻.http: ...

  10. iOS 程序间跳转传参(支付和地图)

    两个APP之间的跳转是通过[[UIApplication sharedApplication] openURL:url]这种方式来实现的. 1.首先设置第一个APP的url地址 2.接着设置第二个AP ...