http://blog.csdn.net/niuox/article/details/9664487

这道题明显是线段树,根据题意可以知道:

(用0和1表示是否包含区间,-1表示该区间内既有包含又有不包含)

U:把区间[l,r]覆盖成1

I:把[-∞,l)(r,∞]覆盖成0

D:把区间[l,r]覆盖成0

C:把[-∞,l)(r,∞]覆盖成0 , 且[l,r]区间0/1互换

S:[l,r]区间0/1互换

这里有两个地方和区间更新不一样

一个是会更新选中区间以外的所有区域,可以这样子解决:

void update(char val,int L,int R,int l,int r,int rt)
{
...
int mid = (l + r)>>;
if (L <= mid)
{
update(val,L,R,l,mid,rt<<);
}
else if(val == 'I' || val == 'C')
{
a[rt<<] = col[rt<<] = ;
}
if(R > mid)
{
update(val,L,R,mid+,r,rt<<|);
}
else if(val == 'I' || val == 'C')
{
a[rt<<|] = col[rt<<|] = ;
}
}

if判断左边是否小于mid,如果不是,那么更新它的左边就是我们想要的选中区域外了,右边同理。

第二个是有两种更新方式,覆盖和异或

这种问题一般需要两种标记,但这里其中一种是覆盖,所以一种标记可以用值自身表示,-1表示杂,非-1表示纯。一个标记数组就行。

然后还要理清两种标记使用的方式

很明显我们可以知道这个性质:

当一个区间被覆盖后,不管之前有没有异或标记都没有意义了
所以当一个节点得到覆盖标记时把异或标记清空

第三种是开闭区间,这里可以通过把所有数乘2处理(偶数表示端点,奇数表示两端点间的区间)。

#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <cctype>
#include <vector>
#include <iterator>
#include <set>
#include <map>
#include <sstream>
using namespace std; #define mem(a,b) memset(a,b,sizeof(a))
#define pf printf
#define sf scanf
#define spf sprintf
#define pb push_back
#define debug printf("!\n")
#define MAXN 65535*2
#define MAX(a,b) a>b?a:b
#define blank pf("\n")
#define LL long long
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define pqueue priority_queue
#define INF 0x3f3f3f3f int n,m; int a[MAXN<<],col[MAXN<<],ans; bool vis[MAXN]; void FXOR(int x)
{
if(a[x]!=-) a[x]^=;
else col[x]^=;
} void PushDown(int rt)
{
if(a[rt] != -)
{
a[rt<<] = a[rt<<|] = a[rt];
col[rt<<] = col[rt<<|] = ;
a[rt] = -;
}
if(col[rt])
{
FXOR(rt<<);
FXOR(rt<<|);
col[rt] = ;
}
} void update(char val,int L,int R,int l,int r,int rt)
{
if(L <= l && r <= R)
{
if(val == 'U')
{
a[rt] = ;
col[rt] = ;
}
else if(val == 'D')
{
a[rt] = col[rt] = ;
}
else if(val == 'C' || val == 'S')
{
FXOR(rt);
}
return;
}
PushDown(rt);
int mid = (l + r)>>;
if (L <= mid)
{
update(val,L,R,l,mid,rt<<);
}
else if(val == 'I' || val == 'C')
{
a[rt<<] = col[rt<<] = ;
}
if(R > mid)
{
update(val,L,R,mid+,r,rt<<|);
}
else if(val == 'I' || val == 'C')
{
a[rt<<|] = col[rt<<|] = ;
}
} void query(int l,int r,int rt)
{
if(a[rt] == )
{
for(int i = l;i<=r;i++) vis[i] = true;
return;
}
else if(a[rt] == ) return;
if(l == r) return;
PushDown(rt);
int mid = (l + r)>>;
query(l,mid,rt<<);
query(mid+,r,rt<<|);
} int main()
{
int r,t;
char op,lchar,rchar;
a[] = col[] = ;
while(~sf("%c %c%d,%d%c\n",&op,&lchar,&r,&t,&rchar))
{
r<<=;
t<<=;
if(lchar == '(') r++;
if(rchar == ')') t--;
update(op,r,t,,MAXN,);
}
query(,MAXN,);
int s = -,e;
bool flag = false;
for(int i=;i<=MAXN;i++)
{
if(vis[i])
{
if(s == -) s = i;
e = i;
}
else
{
if(s!=-)
{
if(flag) pf(" ");
pf("%c%d,%d%c",s&?'(':'[',s>>,(e+)>>,e&?')':']');
s = -;
flag = true;
}
}
}
if(!flag) printf("empty set");
return ; }

POJ 3225 线段树区间更新(两种更新方式)的更多相关文章

  1. POJ 3225 (线段树 区间更新) Help with Intervals

    这道题搞了好久,其实坑点挺多.. 网上找了许多题解,发现思路其实都差不多,所以就不在重复了. 推荐一篇比较好的题解,请戳这. 另外,如果因为可能要更新多次,但最终查询只需要一次,所以没有写pushup ...

  2. HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧)

    HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧) 题意分析 题目大意:一个h*w的公告牌,要在其上贴公告. 输入的是1*wi的w值,这些是公告的尺寸. 贴公告 ...

  3. POJ 3667 线段树区间合并

    http://www.cnblogs.com/scau20110726/archive/2013/05/07/3065418.html 用线段树,首先要定义好线段树的节点信息,一般看到一个问题,很难很 ...

  4. poj 2528 线段树区间修改+离散化

    Mayor's posters POJ 2528 传送门 线段树区间修改加离散化 #include <cstdio> #include <iostream> #include ...

  5. Mayor's posters POJ - 2528 线段树区间覆盖

    //线段树区间覆盖 #include<cstdio> #include<cstring> #include<iostream> #include<algori ...

  6. poj 3468 线段树区间更新/查询

    Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...

  7. hdu 1698+poj 3468 (线段树 区间更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=1698 这个题意翻译起来有点猥琐啊,还是和谐一点吧 和涂颜色差不多,区间初始都为1,然后操作都是将x到y改为z,注 ...

  8. poj 2777 线段树 区间更新+位运算

    题意:有一个长板子,分成多段,有两种操作,第一种是C给从a到b那段染一种颜色c,另一种是P询问a到b有多少种不同的颜色.Sample Input2 2 4  板长 颜色数目 询问数目C 1 1 2P ...

  9. POJ 3667 线段树区间合并裸题

    题意:给一个n和m,表示n个房间,m次操作,操作类型有2种,一种把求连续未租出的房间数有d个的最小的最左边的房间号,另一个操作时把从x到x+d-1的房间号收回. 建立线段树,值为1表示未租出,0为租出 ...

随机推荐

  1. docker下ubutun没有ifconfig命令问题

    解决: apt-get update #更新apt-get apt install net-tools       # ifconfig apt install iputils-ping     # ...

  2. centos虚拟机设置静态ip

    1.虚拟机网络配置设置为桥接模式 2.设置配置文件: vi /etc/sysconfig/network-scripts/ifcfg-ens33 DEVICE=ens33 HWADDR=:0c::c3 ...

  3. liunx 安装 phpstudy

    phpStudy Linux版&Win版同步上线 支持Apache/Nginx/Tengine/Lighttpd/IIS7/8/6 phpStudy for Linux 支持Apache/Ng ...

  4. OJ 21651::Cow Hurdles(佛罗一德的变式)

    Description Farmer John wants the cows to prepare for the county jumping competition, so Bessie and ...

  5. 108th LeetCode Weekly Contest Binary Subarrays With Sum

    In an array A of 0s and 1s, how many non-empty subarrays have sum S? Example 1: Input: A = [1,0,1,0, ...

  6. SPOJ - FREQ2 莫队 / n^1.5logn爆炸

    题意:给定\(a[1...n]\)和\(Q\)次询问,每次统计\([L,R]\)范围内出现频率最高的数的次数 想法没啥好说的,分别统计该数出现的次数和次数出现的次数,然后莫队暴力 注意本题时间卡的很紧 ...

  7. ZOJ - 3624

    当A连向C,B连向D时存在相交路径 #include<bits/stdc++.h> #define rep(i,j,k) for(int i=j;i<=k;i++) #define ...

  8. pageHelper 分页插件使用

    第一步:引入pageHelper的jar包. 链接:https://pan.baidu.com/s/1m3EyAmd_eoAsay0aM7uEkA 提取码:xmfi 第二步:需要在SqlMapConf ...

  9. [转] 完全卸载删除gitlab

    [From] https://yq.aliyun.com/articles/114619 完全卸载删除gitlab 1.停止gitlab gitlab-ctl stop 2.卸载gitlab(注意这里 ...

  10. C++ GUI Qt4编程(11)-5.1hexSpinbox

    1. hexspinbox.cpp /* * The spin box supports integer values but can be extended to use different str ...