POJ 3225 Help with Intervals
来源:互联网 发布:uc高达 知乎 编辑:程序博客网 时间:2024/05/18 15:54
POJ 3225
题目链接:POJ 3225
题意:
一开始S是空集,然后进行5种操作
U L R 将区间[L,R]变成1
I L R 将区间(-oo,L),(R,+oo)变成0
D L R 将区间[L,R]变为0.
C L R 将(-oo,L) (R,+oo)变成0,且[L,R]进行异或操作。
S L R 将区间[L,R]进行异或操作。
分析:
用数组XOR表示是否进行异或操作,cover表示是否转化。
#include <iostream>#include <cstdio>#include <string>#include <algorithm>#include <cmath>using namespace std;#define lson l, mid, rt << 1#define rson mid + 1, r, rt << 1 | 1typedef long long LL;const int maxn = 131072;int k, tn, tcase = 0;bool Hash[maxn];//cover表示区间的0,1状态,XOR表示该区间转换的状态int XOR[maxn<<2],cover[maxn<<2];void pushup(int rt){//表示整个区间可以同时转换 if(cover[rt]!=-1)cover[rt]^=1;else XOR[rt]^=1;}void pushdown(int rt){ if(cover[rt]!=-1) { cover[rt<<1]=cover[rt<<1|1]=cover[rt];XOR[rt<<1]=XOR[rt<<1|1]=0; cover[rt]=-1;; }//表示该点转换了但是孩子未转换if(XOR[rt]){pushup(rt<<1);pushup(rt<<1|1);XOR[rt]=0;}}void update(char op,int L, int R,int l, int r, int rt){ if (L <= l && R>= r) // L<=l<=r<=R { if(op=='U')cover[rt]=1,XOR[rt]=0; else if(op=='D')cover[rt]=0,XOR[rt]=0; else if(op=='C'||op=='S')pushup(rt); return ; } pushdown(rt); int mid = (l + r) >> 1; if (L <= mid) update(op,L, R, lson);else if(op=='I'||op=='C')cover[rt<<1]=XOR[rt<<1]=0; if (R > mid) update(op,L, R, rson);else if(op=='I'||op=='C')cover[rt<<1|1]=XOR[rt<<1|1]=0;}void query(int l, int r, int rt){if(cover[rt]==1){for(int i=l;i<=r;i++)Hash[i]=true;return ;}if(cover[rt]==0)return ; if(l==r)return ;pushdown(rt); int mid = (l + r) >> 1; query(lson); query(rson);}int main(){// freopen("in.txt","r",stdin);char op,l,r;int a,b; while(scanf("%c %c%d,%d%c",&op,&l,&a,&b,&r)!=EOF) { a<<=1;b<<=1; if(l=='(') a++; if(r==')') b--; if(a>b)//比如输入区间为I (1,1)或C (1,1) { if(op=='C'||op=='I')//将-oo~l,r~+oo标记为0 {cover[1]=XOR[1]=0; } } else update(op,a,b,0,maxn,1); getchar(); } query(0,maxn,1); int ok=0,s=-1,e;for(int i=0;i<maxn;i++){if(Hash[i]){if(s==-1)s=i;e=i;}else {if(s!=-1){if(ok)printf(" ");else ok=1;printf("%c%d,%d%c",s&1?'(':'[',s>>1,(e+1)>>1,e&1?')':']');s=-1;}}} if(!ok)printf("empty set");printf("\n");return 0;}
0 0
- POJ 3225 - Help with Intervals
- POJ 3225 - Help with Intervals
- POJ 3225 Help with Intervals
- Poj 3225 Help with Intervals
- POJ 3225 Help with Intervals
- POJ 3225 Help with Intervals
- poj-3225-Help with Intervals
- POJ-3225 Help with Intervals
- poj 3225 Help with Intervals
- poj 3225 Help with Intervals
- POJ 3225 Help with Intervals
- POJ 3225 Help with Intervals
- POJ 3225 Help with Intervals
- POJ 3225 Help with Intervals 线段树
- poj 3225 Help with Intervals(过题啦啦~)
- POJ 3225 Help with Intervals 线段树
- POJ 3225 Help with Intervals 线段树
- poj 3225 Help with Intervals[线段树]
- 如何将R与SQL Server连接起来
- 黑马程序员IOS-C语言-结构体、枚举
- Queue学习
- 图像处理(九)人物肖像风格转换-Siggraph 2014
- DataFlash
- POJ 3225 Help with Intervals
- Linux Futex浅析
- RadioGroup实现仿新浪微博的效果
- 杭电ACM 2030:汉字统计
- LITTLE SHOP OF FLOWERS
- Leetcode Merge Two Sorted Lists 合并两个有序链表
- Code我的人生
- 用adb logcat抓取log
- poj 3662 二分+最短路,求第k大最小权值