Result : Accepted Memory : 4328 KB Time : 1141 ms
/* * Author: Gatevin * Created Time: 2015/8/17 13:50:53 * File Name: Sakura_Chiyo.cpp */ #include<iostream> #include<sstream> #include<fstream> #include<vector> #include<list> #include<deque> #include<queue> #include<stack> #include<map> #include<set> #include<bitset> #include<algorithm> #include<cstdio> #include<cstdlib> #include<cstring> #include<cctype> #include<cmath> #include<ctime> #include<iomanip> using namespace std; const double eps(1e-8); typedef long long lint; #define maxn 66666*2 struct Segment_Tree { #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 int flag[maxn << 2]; int cover[maxn << 2]; bool vis[maxn]; void pushUp(int rt) { if(cover[rt << 1] == cover[rt << 1 | 1] && cover[rt << 1] != -1) cover[rt] = cover[rt << 1]; else cover[rt] = -1; } void pushDown(int l, int r, int rt, int mid) { if(cover[rt] != -1) { cover[rt << 1] = cover[rt << 1 | 1] = cover[rt]; flag[rt << 1] = flag[rt << 1 | 1] = 0; cover[rt] = -1; } if(flag[rt]) { if(cover[rt << 1] != -1) cover[rt << 1] ^= flag[rt]; else flag[rt << 1] ^= flag[rt]; if(cover[rt << 1 | 1] != -1) cover[rt << 1 | 1] ^= flag[rt]; else flag[rt << 1 | 1] ^= flag[rt]; flag[rt] = 0; } } void update(int l, int r, int rt, int L, int R, int value)//更新区间[L, R]值为value { if(l >= L && r <= R) { cover[rt] = value; flag[rt] = 0; return; } int mid = (l + r) >> 1; pushDown(l, r, rt, mid); if(mid >= L) update(lson, L, R, value); if(mid + 1 <= R) update(rson, L, R, value); pushUp(rt); } void update(int l, int r, int rt, int L, int R)//更新区间[L, R]值为原来的反(异或1) { if(l >= L && r <= R) { if(cover[rt] != -1) cover[rt] ^= 1; else flag[rt] ^= 1; return; } int mid = (l + r) >> 1; pushDown(l, r, rt, mid); if(mid >= L) update(lson, L, R); if(mid + 1 <= R) update(rson, L, R); pushUp(rt); } void query(int l, int r, int rt) { if(cover[rt] != -1) { if(cover[rt] == 1) for(int i = l; i <= r; i++) vis[i] = 1; return; } int mid = (l + r) >> 1; pushDown(l, r, rt, mid); query(lson); query(rson); pushUp(rt); } }; Segment_Tree ST; int main() { ST.cover[1] = 0; ST.flag[1] = 0; memset(ST.vis, 0, sizeof(ST.vis)); char op[4], lb, rb; int l, r; while(scanf("%s %c%d,%d%c", op, &lb, &l, &r, &rb) != EOF) { l = (l << 1) + 1; r = (r << 1) - 1; if(lb == '[') l--; if(rb == ']') r++; if(l > r) { if(op[0] == 'C' || op[0] == 'I') ST.cover[1] = ST.flag[1] = 0; continue; } switch(op[0]) { case 'U': ST.update(0, maxn, 1, l, r, 1);//S = S并T break; case 'I': if(l - 1 >= 0) ST.update(0, maxn, 1, 0, l - 1, 0);//S = S交T if(r + 1 <= maxn) ST.update(0, maxn, 1, r + 1, maxn, 0); break; case 'D': ST.update(0, maxn, 1, l, r, 0);//S = S - T break; case 'C': if(l - 1 >= 0) ST.update(0, maxn, 1, 0, l - 1, 0);//S = T - S if(r + 1 <= maxn) ST.update(0, maxn, 1, r + 1, maxn, 0); ST.update(0, maxn, 1, l, r); break; case 'S': ST.update(0, maxn, 1, l, r);//S = (S - T)并(T - S) break; } } ST.query(0, maxn, 1); bool found = 0; l = 0; while(l <= 65535*2) { if(!ST.vis[l]) { l++; continue; } r = l; while(r + 1 <= 65535*2 && ST.vis[r + 1]) r++; int tr = r; char le, ri; if(l & 1) { le = '('; l = (l - 1) / 2; } else { le = '['; l = l / 2; } if(r & 1) { ri = ')'; r = (r + 1) / 2; } else { ri = ']'; r = r / 2; } if(found) printf(" "); printf("%c%d,%d%c", le, l, r, ri); found = 1; l = tr + 1; } if(!found) puts("empty set"); else puts(""); return 0; }