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 application framework 分析[in process]

    application activity application service application UI system application sdk tool JVM 1 activity t ...

  2. ios+openflow 问题

    环境:xcode5.1+ios7.1 需求:A试图 的scroll加入 B视图:[A addSubview:B.view] 问题: 1.B视图载入到A视图上了,但Openflow的图片未载入.后经调试 ...

  3. Android studio 分32位64位版本吗?

    下载的时候,是不分32位和64位的.安装完成之后,在bin目录下,有studio.exe和studio64.exe这两个文件.前一个是32位的,后一个是64位的.根据自己的电脑进行选择.

  4. Oracle11g数据库导入Oracle10g数据库操作笔记

    一.在11g服务器上,使用expdp命令备份数据 EXPDP USERID='SYS/sys@daggis as sysdba' schemas=oa directory=DATA_PUMP_DIR ...

  5. Elasticsearch之重要核心概念(cluster(集群)、shards(分配)、replicas(索引副本)、recovery(据恢复或叫数据重新分布)、gateway(es索引的持久化存储方式)、discovery.zen(es的自动发现节点机制机制)、Transport(内部节点或集群与客户端的交互方式)、settings(修改索引库默认配置)和mappings)

    Elasticsearch之重要核心概念如下: 1.cluster 代表一个集群,集群中有多个节点,其中有一个为主节点,这个主节点是可以通过选举产生的,主从节点是对于集群内部来说的.es的一个概念就是 ...

  6. LeetCode hard 668. Kth Smallest Number in Multiplication Table(二分答案,一次过了,好开心,哈哈哈哈)

    题目:https://leetcode.com/problems/kth-smallest-number-in-multiplication-table/description/ 668. Kth S ...

  7. STM8S103之中断优先级设置

    STM8S的中断由中断控制器(ITC)控制.STM8所有IO都支持中断,分为PA~PE 5个组,每组IO对应一个中断服务函数(也就是每组IO只有一个向量).STM8没有专门的中断状态寄存器,所以只能通 ...

  8. js指定区域全屏

    <html>     <head>         <title>js指定区域全屏</title>         <style>      ...

  9. PHP SOAP 教程

    一.SoapServer 服务器 1.__construct 作用:创建 SoapServer 对象 用法:__construct ( mixed wsdl [, array options] ) 参 ...

  10. 注解形式读取properties文件中的属性

    1.spring.xml中加入(多个properties 用逗号隔开)  <context:property-placeholder location="classpath:jdbc. ...