# [bzoj 3226]校门外的区间

### 题解

py一下输入数据，然后操作变成：

U 区间涂1
I 两侧区间涂0
D 区间涂0
C 两侧涂0,中间取反
S 区间取反

#include<map>
#include<stack>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<complex>
#include<iostream>
#include<assert.h>
#include<algorithm>
using namespace std;
#define inf 1001001001
#define infll 1001001001001001001LL
#define ll long long
#define dbg(vari) cerr<<#vari<<" = "<<(vari)<<endl
#define gmax(a,b) (a)=max((a),(b))
#define gmin(a,b) (a)=min((a),(b))
#define Ri register int
#define gc getchar()
#define il inline
Ri x=0,f=0;char ch;
while(!isdigit(ch=gc))if(ch=='(')f=-1;
while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=gc;}
if(ch==')')f=1;
return x*2-f;
}
#define FO(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
#define N 131073
char ch[5];
struct seg{int l,r,val,tag,rev;}t[4*N];
void build(int k,int l,int r){
t[k]=(seg){l,r,0,-1,0};
if(l==r)    return;
int mid=(l+r)>>1;
build(k<<1,l,mid);
build(k<<1|1,mid+1,r);
}
void pushdown(int k){
int tag=t[k].tag,rev=t[k].rev;
t[k].tag=-1;t[k].rev=0;
if(t[k].l==t[k].r){
if(tag!=-1)t[k].val=tag;
t[k].val^=rev;;
return;
}
if(tag!=-1){
t[k<<1].tag=t[k<<1|1].tag=tag;
t[k<<1].rev=t[k<<1|1].rev=0;
}
t[k<<1].rev^=rev;t[k<<1|1].rev^=rev;
}
int query(int k,int x){
pushdown(k);
int l=t[k].l,r=t[k].r;
if(l==r)    return t[k].val;
int mid=(l+r)>>1;
if(x<=mid)
return query(k<<1,x);
else
return query(k<<1|1,x);
}
void modify(int k,int x,int y,int val){
if(y<x)return;
pushdown(k);
int l=t[k].l,r=t[k].r;
if(l==x&&y==r){
if(val==-1)    t[k].rev^=1;
else t[k].tag=val;
return;
}
int mid=(l+r)>>1;
if(y<=mid)
modify(k<<1,x,y,val);
else if(x>mid)
modify(k<<1|1,x,y,val);
else {
modify(k<<1,x,mid,val);
modify(k<<1|1,mid+1,y,val);
}
}
int main(){
build(1,1,N);
while(scanf("%s",ch)!=EOF){
int a=gi,b=gi;
a+=2;b+=2;
switch(ch[0]){
case 'U':modify(1,a,b,1);break;
case 'I':modify(1,1,a-1,0);modify(1,b+1,N,0);break;
case 'D':modify(1,a,b,0);break;
case 'C':modify(1,1,a-1,0);modify(1,b+1,N,0);modify(1,a,b,-1);break;
case 'S':modify(1,a,b,-1);break;
}
}
int start=-1,last=-1,flag=0;
for(int i=1;i<=N;i++)
if(query(1,i)){
if(start==-1)start=i;
last=i;
}
else{
if(start!=-1){
if(flag)printf(" ");else flag=1;
if(start&1)    printf("(");
else    printf("[");
printf("%d,%d",start/2-1,(last+1)/2-1);
if(last&1)printf(")");
else printf("]");
}
last=start=-1;
}
if(!flag)puts("empty set");
return 0;
}
posted @ 2016-09-28 13:42 zhouyis 阅读(...) 评论(...) 编辑 收藏