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. [Angular] Handle HTTP Errors in Angular with HttpErrorResponse interface

    When communicating with some backend API, data travels over the network using the HTTP protocol. As ...

  2. Linux 0.11中write实现

    看了一下Linux 0.11版本号write的实现,首先它在标准头文件unistd.h中有定义 int write(int fildes, const char * buf, off_t count) ...

  3. 50.AngularJs directive详解及示例代码

    转自:https://www.cnblogs.com/best/tag/Angular/ 本教程使用AngularJs版本:1.5.3 AngularJs GitHub: https://github ...

  4. .net core 实现npoi导出

    Nuget 安装 NPOI 2.4.1 工作时间写着测试玩玩 public void ExportDataToExcel() { var workbook = new HSSFWorkbook(); ...

  5. xBIM 高级02 插入复制功能

    系列目录    [已更新最新开发文章,点击查看详细]  IFC 模型中的合并和删除实体是一个非常重要的任务,因为 IFC 不是一个分层结构.它是一个复杂的结构,具有潜在的循环关系,是一个双向导航.在单 ...

  6. (转载)15 个 Android 通用流行框架大全

    15 个 Android 通用流行框架大全 时间:2017-03-20 11:36来源:未知 作者:admin 点击: 2089 次 15 个 Android 通用流行框架大全   1. 缓存 Dis ...

  7. 51nod 1562 玻璃切割 (STL map+一点点的思考)

    1562 玻璃切割 题目来源: CodeForces 基准时间限制:1.5 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 现在有一块玻璃,是长方形的(w 毫米× h 毫米),现在要 ...

  8. 结构化数据、半结构化数据、非结构化数据——Hadoop处理非结构化数据

    刚开始接触Hadoop ,指南中说Hadoop处理非结构化数据,学习数据库的时候,老师总提结构化数据,就是一张二维表,那非结构化数据是什么呢?难道是文本那样的文件?经过上网搜索,感觉这个帖子不错 网址 ...

  9. Linux停止tomcat运行

    打开终端cd /java/tomcat#执行bin/startup.sh #启动tomcatbin/shutdown.sh #停止tomcattail -f logs/catalina.out #看t ...

  10. axios使用方法

    npm install axios 创建文件夹api/index.js import axios from 'axios'; let http = axios.create({ baseURL: '' ...