lazy写崩了…….

查了好久

/*

U—> [l,r]–>1

I—> [1,l-1] [r+1,+无穷] –>0

D—> [l,r]–>0

C—> [1,l-1] [r+1,+无穷]–>0 xor[l,r]

S—> [l,r]–>xor

*/

//By SiriusRen
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define maxn 140000
struct Tree{int lazy;bool cover;Tree(){lazy=-1;}}tree[maxn*16];//=0 不选 =1 选 =2 xor
int xx,yy,vis[maxn*2];
char op,Left,Right,f;
void push_down(int pos){
int lson=pos<<1,rson=pos<<1|1;
if(tree[pos].lazy==2){
if(tree[lson].lazy==-1)tree[lson].lazy=2,tree[lson].cover=!tree[lson].cover;
else if(tree[lson].lazy==2)tree[lson].lazy=-1,tree[lson].cover=!tree[lson].cover;
else tree[lson].lazy=!tree[lson].lazy,tree[lson].cover=!tree[lson].cover;
if(tree[rson].lazy==-1)tree[rson].lazy=2,tree[rson].cover=!tree[rson].cover;
else if(tree[rson].lazy==2)tree[rson].lazy=-1,tree[rson].cover=!tree[rson].cover;
else tree[rson].lazy=!tree[rson].lazy,tree[rson].cover=!tree[rson].cover;
}
else tree[lson].cover=tree[rson].cover=tree[pos].lazy,tree[lson].lazy=tree[rson].lazy=tree[pos].lazy;
tree[pos].lazy=-1;
}
void update(int l,int r,int pos,int L,int R,int id){
if(l>=L&&r<=R){
if(id!=2)tree[pos].cover=id,tree[pos].lazy=id;
else{
if(tree[pos].lazy==-1)tree[pos].lazy=2;
else if(tree[pos].lazy==2)tree[pos].lazy=-1;
else tree[pos].lazy=!tree[pos].lazy;
tree[pos].cover=!tree[pos].cover;
}
return;
}
if(~tree[pos].lazy)push_down(pos);
int mid=(l+r)>>1,lson=pos<<1,rson=pos<<1|1;
if(mid>=R)update(l,mid,lson,L,R,id);
else if(mid<L)update(mid+1,r,rson,L,R,id);
else update(l,mid,lson,L,R,id),update(mid+1,r,rson,L,R,id);
}
void query(int l,int r,int pos,int x){
if(~tree[pos].lazy)push_down(pos);
if(l==r){vis[l]=tree[pos].cover;return;}
int mid=(l+r)>>1,lson=pos<<1,rson=pos<<1|1;
if(mid>=x)query(l,mid,lson,x);
else query(mid+1,r,rson,x);
}
int main(){
while(scanf("%c %c%d,%d%c",&op,&Left,&xx,&yy,&Right)!=EOF){
xx<<=1,yy<<=1;
if(Left=='(')xx++;if(Right==')')yy--;
if(xx>yy)xx=yy=maxn-1;
if(op=='U')update(0,maxn,1,xx,yy,1);
else if(op=='I'){
if(xx)update(0,maxn,1,0,xx-1,0);
update(0,maxn,1,yy+1,maxn,0);
}
else if(op=='D')update(0,maxn,1,xx,yy,0);
else if(op=='C'){
if(xx)update(0,maxn,1,0,xx-1,0);
update(0,maxn,1,yy+1,maxn,0);
update(0,maxn,1,xx,yy,2);
}
else if(op=='S')update(0,maxn,1,xx,yy,2);
getchar();
}
for(int i=0;i<maxn;i++)query(0,maxn,1,i);
xx=-1;
for(int i=0;i<135000;i++){
if(vis[i]&&~xx)yy=i;
else if(!vis[i]){
if(~xx){
if(f)printf(" ");
if(!f)f=1;
if(xx&1)putchar('(');
else putchar('[');
printf("%d,%d",xx>>1,(yy+1)>>1);
if(yy&1)putchar(')');
else putchar(']');
}
xx=-1;
}
else if(vis[i]&&xx==-1)xx=yy=i;
}
if(!f)printf("empty set");
}

POJ 3225 线段树+lazy标记的更多相关文章

  1. POJ 2777——线段树Lazy的重要性

    POJ 2777 Count Color --线段树Lazy的重要性 原题 链接:http://poj.org/problem?id=2777 Count Color Time Limit: 1000 ...

  2. poj 2777(线段树+lazy思想) 小小粉刷匠

    http://poj.org/problem?id=2777 题目大意 涂颜色,输入长度,颜色总数,涂颜色次数,初始颜色都为1,然后当输入为C的时候将x到y涂为颜色z,输入为Q的时候输出x到y的颜色总 ...

  3. poj3468 线段树+lazy标记

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 92921   ...

  4. POJ3237 Tree(树剖+线段树+lazy标记)

    You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edges are numbe ...

  5. 线段树+lazy标记 2019年8月10日计蒜客联盟周赛 C.小A的题

    题目链接:https://nanti.jisuanke.com/t/40852 题意:给定一个01串s,进行m次操作,|s|<=1e6,m<=5e5 操作有两种 l r 0,区间[l,r] ...

  6. poj 3225 线段树+位运算

    略复杂的一道题,首先要处理开闭区间问题,扩大两倍即可,注意输入最后要\n,初始化不能随便memset 采用线段树,对线段区间进行0,1标记表示该区间是否包含在s内U T S ← S ∪ T 即将[l, ...

  7. POJ 3225 线段树区间更新(两种更新方式)

    http://blog.csdn.net/niuox/article/details/9664487 这道题明显是线段树,根据题意可以知道: (用0和1表示是否包含区间,-1表示该区间内既有包含又有不 ...

  8. HDU_1698 Just a Hook(线段树+lazy标记)

    pid=1698">题目请点我 题解: 接触到的第一到区间更新,须要用到lazy标记.典型的区间着色问题. lazy标记详情请參考博客:http://ju.outofmemory.cn ...

  9. poj 3468(线段树+lazy思想)

    题目链接:http://poj.org/problem?id=3468 思路:如果直接去做,每次都更新到叶子节点,那必然会TLE,我们可以采用lazy的思想:没必要每次更新都更新到叶子节点,只要有一个 ...

随机推荐

  1. 非典型的scala程序及其编译后的结果

    初学Scala Folder structure以及部分代码 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2xldmVyd3lx/font/5a6L5L ...

  2. POJ 1496 POJ 1850 组合计数

    Code Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8256 Accepted: 3906 Description Tran ...

  3. 最全Pycharm教程(29)——再探IDE,速成手冊

    1.准备工作 (1)确认安装了Python解释器,版本号2.4到3.4均可. (2)注意Pycharm有两个公布版本号:社区版和专业版,详见 Edition Comparison Matrix 2.初 ...

  4. 去除iframe滚动条

    主页面的IFRAME中添加:scrolling="yes" 子页面程序代码: 让竖条消失: <body style='overflow:scroll;overflow-x:a ...

  5. dll开发

    _declspec(dllexport) void fun() { }

  6. (转载)Android中的Service:Binder,Messenger,AIDL(2)

    前言 前面一篇博文介绍了关于Service的一些基本知识,包括service是什么,怎么创建一个service,创建了一个service之后如何启动它等等.在这一篇博文里有一些需要前一篇铺垫的东西,建 ...

  7. php--tp5在查询到的数据中添加新字段

  8. Thread Control Block

    Thread Control Block The following is the declaration of the Thread Control Block. struct tcb { u32_ ...

  9. plsql 查询历史执行语句

    control+e. 如果执行删除.修改.增加的操作,未提交的历史记录中也有.

  10. 关于目标检测 Object detection

    NO1.目标检测 (分类+定位) 目标检测(Object Detection)是图像分类的延伸,除了分类任务,还要给定多个检测目标的坐标位置.      NO2.目标检测的发展 R-CNN是最早基于C ...