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. cf #257(Div.2) A. Jzzhu and Children

    A. Jzzhu and Children time limit per test 1 second memory limit per test 256 megabytes input standar ...

  2. CSS3弹性布局内容对齐(justify-content)属性使用具体解释

    内容对齐(justify-content)属性应用在弹性容器上.把弹性项沿着弹性容器的主轴线(main axis)对齐. 该操作发生在弹性长度以及自己主动边距被确定后. 它用来在存在剩余空间时怎样加以 ...

  3. 根据数据库表结构生成java类

    import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWrit ...

  4. (转)PHP(其他语言类似)编码的规范性

    为了提高工作效率,保证开发的有效性和合理性,并最大程度提高程序代码的可读性和可重复利用性,提高沟通效率,需要一份代码编辑规范.         一.文件标记:            1.所有php文件 ...

  5. 你不知道的JavaScript(六)Box&Unbox

    很多语言中都有Box和Unbox的概念,很多书籍把Box翻译为"装箱操作",指的是將基本数据类型包装成对象:Unbox和它相反,把对象类型转换为基本类型. 我们知道JavaScri ...

  6. Pyinstaller 0

    Pyinstaller 是一个小的可以打包我们所写的Python脚本,来生成相应的可执行文件. 它是怎么工作的? PyInstaller读取您编写的Python脚本.它会分析您的代码,以发现您的脚本执 ...

  7. 【原创】TimeSten安装与配置

    1.安装TimeSten 2.安装时要指定TNS_ADMIN_LOCATION,即tnsnames.ora的路径,因为tt会根据这个连接Oracle.C:\TimesTen\tt1122_32\net ...

  8. solarwinds之数据库

      1.              Orion配置向导     2.              连接数据库     3.              创建一个新的数据库     4.           ...

  9. php——get与post方法(转)

    file_get_contents版本: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 <?php /**  * 发送p ...

  10. Node_进阶_7

    Node进阶第七天 一.复习 一.索引   数据库中,根据一个字段的值,来寻找一个文档,是很常见的操作.比如根据学号来找一个学生.这个学号是唯一的.只要有学号,就能唯一确认一个学生的文档.学号这个属性 ...