//poj 3225
#include <iostream>
using namespace std;
#define lx (x<<1)
#define rx ((x<<1)|1)
#define MID ((l+r)>>1)
const int MAXN=140000;
int cover[MAXN<<2];
int XOR[MAXN<<2];
bool vis[MAXN+10];
void FXOR(int x)
{
if(cover[x]!=-1) cover[x]^=1;
else XOR[x]^=1;
}
void pushDown(int x)
{
if(cover[x]!=-1){
cover[lx]=cover[rx]=cover[x];
XOR[lx]=XOR[rx]=0;
cover[x]=- 1;
}
if(XOR[x]){
FXOR(lx);
FXOR(rx);
XOR[x]=0;
}
}
void update(int L,int R,char op,int l,int r,int x)
{
if(L<=l&&r<=R){
if(op=='U'){
cover[x]=1;
XOR[x]=0;
}else if(op=='D'){
cover[x]=0;
XOR[x]=0;
}else if(op=='C') FXOR(x);
else if(op=='S') FXOR(x);
return ;
}
pushDown(x);
if(L<=MID) update(L,R,op,l,MID,lx);
else if(op=='I'||op=='C') cover[lx]=XOR[lx]=0;
if(MID<R) update(L,R,op,MID+1,r,rx);
else if(op=='I'||op=='C') cover[rx]=XOR[rx]=0;
}
void query(int l,int r,int x)
{
if(cover[x]==1){
for(int i=l;i<=r;++i)
vis[i]=true;
return ;
}
if(cover[x]==0)
return ;
if(l==r)
return ;
pushDown(x);
query(l,MID,lx);
query(MID+1,r,rx);
}
int main()
{
int a,b;
char op,lchar,rchar;
while(scanf("%c %c%d,%d%c\n",&op,&lchar,&a,&b,&rchar)==5){
a<<=1;
b<<=1;
if(lchar=='(') ++a;
if(rchar==')') --b;
update(a,b,op,0,MAXN,1);
}
query(0,MAXN,1);
int s=-1,e;
bool flag=false;
for(int i=0;i<=MAXN;++i){
if(vis[i]==1){
if(s==-1)
s=i;
e=i;
}else{
if(s!=-1){
if(flag) printf(" ");
printf("%c%d,%d%c",s&1?'(':'[',s/2,(e+1)/2,e&1?')':']');
s=-1;
flag=true;
}
}
}
if(!flag) printf("empty set");
puts("");
return 0;
}
poj 3225 Help with Intervals 线段树lazy-tag求解区间运算
最新推荐文章于 2019-05-11 22:31:43 发布