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. android 读取xml

    在有些应用中,有一点小数据.直接存储在XML就是.实现较为简单, 1.xml文件放入asset目录.结构如: <?xml version="1.0" encoding=&qu ...

  2. 主站sinox.org堵塞太厉害,大家用sinox.3322.org訪问

    近期 www.sinox.org域名堵塞太厉害了.差点儿不能訪问,如今大家用sinox.3322.org訪问 sinox.org仅仅是显示正在建设 一直以来sinox.org仅仅是个摆设,并非主要域名 ...

  3. 超便携式截屏录屏软件FastStone Capture

    超便携式截屏录屏软件FastStone Capture

  4. linux 内存不足时候 应该及时回收page cache

    另一起问题是24G内存的系统,空闲内存已经不到50M 1. 确认该系统的版本是64位 # uname -a Linux gxgd-nms-app 2.6.18-194.el5xen #1 SMP Tu ...

  5. spring中bean标签factory-method和factory-bean)详解工厂方法(factory-method和factory-bean)

    转自:http://blog.sina.com.cn/s/blog_6d3c1ec601019f3j.html A.factory-method The name of a factory metho ...

  6. java中对象和对象引用的区别

    1.何谓对象? 在Java中有一句比较流行的话,叫做“万物皆对象”,这是Java语言设计之初的理念之一.要理解什么是对象,需要跟类一起结合起来理解.下面这段话引自<Java编程思想>中的一 ...

  7. Android VelocityTracker类和Scroller类

    VelocityTracker类:用于跟踪触屏事件的速度,通常使用VelocityTracker的步骤如下: static VelocityTracker obtain():获取一个VelocityT ...

  8. vue 初始化项目模板报错

    E:\xiaogezi.cn\vue>vue init webpack myProject vue-cli · Failed to download repo vuejs-templates/w ...

  9. Codeforces 845A. Chess Tourney 思路:简单逻辑题

    题目: 题意:输入一个整数n,接着输入2*n个数字,代表2*n个选手的实力.    实力值大的选手可以赢实力值小的选手,实力值相同则都有可能赢.    叫你把这2*n个选手分成2个有n个选手的队伍. ...

  10. Matlab---从入门到精通 Chapter 4 编程基础

    ---恢复内容开始--- 4-1 M文件编辑器 在命令窗口输入edit命令,可以打开M文件编辑器,创建新的M文件 在命令行中输入edit filename,那么可以打开在当前目录环境下的M文件 4-2 ...