bzoj 3226 [Sdoi2008]校门外的区间(线段树)
3226: [Sdoi2008]校门外的区间
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 615 Solved: 227
[Submit][Status][Discuss]
Description
|
U T
|
S∪T
|
|
I T
|
S∩T
|
|
D T
|
S-T
|
|
C T
|
T-S
|
|
S T
|
S⊕T
|
|
A∪B
|
{x : xÎA or xÎB}
|
|
A∩B
|
{x : xÎA and xÎB}
|
|
A-B
|
{x : xÎA and xÏB}
|
|
A⊕B
|
(A-B)∪(B-A)
|
Input
Output
Sample Input
D [3,3]
S [2,4]
C (1,5)
I (2,3]
Sample Output
HINT
对于 100% 的数据,0≤a≤b≤65535,1≤M≤70000
Source
【思路】
线段树。
因为开区间所以扩大一倍就好了。
转化集合操作为线段树上的操作
U 将a,b设为1
I 将1..a-1,b+1..n设为0
D 将a..b设为0
C 将1..a-1,b+1..n设为0 取反a..b
S 取反a..b
写一个支持set与取反的线段树。
【代码】
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std; const int N = +; struct Tree{ int l,r,v,setv,rev; }T[N<<]; void build(int u,int L,int R) {
T[u].l=L,T[u].r=R,T[u].setv=-;T[u].rev=;
if(L==R) return ;
int M=(L+R)>>;
build(u<<,L,M); build(u<<|,M+,R);
}
void pushdown(int u) {
int lc=u<<,rc=lc|;
if(T[u].l==T[u].r) {
if(T[u].setv!=-) T[u].v=T[u].setv;
T[u].v^=T[u].rev;
}
else {
if(T[u].setv!=-) { //AT: set->rev=0 所以rev的执行顺序在set之后
T[lc].setv=T[rc].setv=T[u].setv;
T[lc].rev=T[rc].rev=;
}
T[lc].rev^=T[u].rev,T[rc].rev^=T[u].rev;
}
T[u].setv=-, T[u].rev=;
}
void update(int u,int L,int R,int x) {
pushdown(u);
if(L<=T[u].l && T[u].r<=R) {
if(x==-) T[u].rev^=;
else T[u].setv=x;
}
else {
int M=(T[u].l+T[u].r)>>;
if(L<=M) update(u<<,L,R,x);
if(M<R) update(u<<|,L,R,x);
}
}
int query(int u,int x) {
pushdown(u);
if(T[u].l==T[u].r) return T[u].v;
else {
int M=(T[u].l+T[u].r)>>;
if(x<=M) return query(u<<,x);
else return query(u<<|,x);
}
}
void reverse(int u,int L,int R) { update(u,L,R,-); } char s[];
void read(int& x) {
char c=getchar(); int f=; x=;
while(!isdigit(c)) { if(c=='(') f=; c=getchar(); }
while(isdigit(c))
x=x*+c-'' , c=getchar();
if(c==')') f=-;
x=x*+f;
}
int main() {
//freopen("in.in","r",stdin);
//freopen("out.out","w",stdout);
int n=*+;
build(,,n);
while(scanf("%s",s)==) {
int a,b;
read(a),read(b);
a+=; b+=;
switch(s[]) {
case 'U':
update(,a,b,); break;
case 'I':
update(,,a-,),update(,b+,n,); break;
case 'D':
update(,a,b,); break;
case 'C':
update(,,a-,),update(,b+,n,);
reverse(,a,b); break;
case 'S':
reverse(,a,b); break;
}
}
int f=-,r=-,flag=;
for(int i=;i<=n;i++)
{
if(query(,i)) { if(f==-) f=i; r=i; }
else {
if(f!=-) {
if(flag) putchar(' ');
else flag=;
if(f&) putchar('(');
else putchar('[');
printf("%d,%d",f/-,(r+)/-);
if(r&) putchar(')');
else putchar(']');
}
f=r=-;
}
}
if(!flag) puts("empty set");
return ;
}
bzoj 3226 [Sdoi2008]校门外的区间(线段树)的更多相关文章
- BZOJ 3226: [Sdoi2008]校门外的区间
题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3226 题意:初始集合S为空.模拟四种集合操作:集合并.交.差.补集并. 思路:区间 ...
- [SDOI2008] 校门外的区间 - 线段树
U T 即将区间 \(T\) 范围赋值为 \(1\) I T 即将区间 \(U - T\) 范围赋值为 \(0\) D T 即将区间 \(T\) 赋值为 \(0\) C T 由于 \(S=T-S=T( ...
- [bzoj3226][Sdoi2008]校门外的区间——线段树
题目 略 题解 直接套黄学长模板. Orz 代码 #include <bits/stdc++.h> using namespace std; #define ll long long #d ...
- 3226. [SDOI2008]校门外的区间【线段树】
Description 受校门外的树这道经典问题的启发,A君根据基本的离散数学的知识,抽象出5种运算维护集合S(S初始为空)并最终输出S.现在,请你完成这道校门外的树之难度增强版——校门外的区间. ...
- 3226: [Sdoi2008]校门外的区间
链接 思路 bug漫天飞... 维护一颗线段树,支持区间赋值,和区间异或.因为会处理到一些方括号还是圆括号的问题,所以对于每一个下标都乘2,假设中间有一个.5即可,都变成了方括号,输出在处理一下. U ...
- BZOJ-3226 校门外的区间 线段数+拆点(类似的思想)
shabi题....bzoj关键字检查freopen??可怕,,1A的卡了一小时.... 3226: [Sdoi2008]校门外的区间 Time Limit: 10 Sec Memory Limit: ...
- BZOJ3226[Sdoi2008]校门外的区间 题解
题目大意: 有5种运算维护集合S(S初始为空)并最终输出S. 5种运算如下: U T S∪T I T S∩T D T S-T C T T-S S T S⊕T 基本集合运算如下: A∪B {x : ...
- 「BZOJ3226」[Sdoi2008]校门外的区间
题目 首先是开闭区间的处理,我们把\(1.5\)这种数加进来,用\([1.5,6]\)来表示\((2,6]\) 根据离散数学的基本知识,尝试把五个操作转化成人话 把\([x,y]\)变成\(1\) 把 ...
- BZOJ3226: [Sdoi2008]校门外的区间
感觉很有趣的题呢. 每个点拆成两个,线段树维护. 不过这题难点其实在输入输出. #include<bits/stdc++.h> #define N (1<<17) #defin ...
随机推荐
- IOS 学习笔记 2015-03-24 OC-API-不可变字符串
大部分是模仿// // main.m // OC-API-不可变字符串 // // Created by wangtouwang on 15/3/25. // Copyright (c) 2015年 ...
- IOS 学习日志 2015-3-17
Objective--C 一 关键字 @class 导入已有的类 id 对象类型 表示任何一个ObjC对象类型 Block 对象类型 OC中称为代码块 类似于C中的函数式指针 typedef 定义数据 ...
- 多语言文本资源的访问(Windows:ini)
目标 本文要讨论对于开发多语言界面程序所需要解决的一个问题,即文本资源组织及访问的方法. 本文主要以Windows平台下讨论具现并提供处理代码. Windows方案 Windows下界面开发,除Dir ...
- 【ADO.NET】6、SQLHelper简单封装
using System.Data.SqlClient;using System.Configuration;引用:System.Configuration 连接字符串放到配置文件中 新建一个类,写如 ...
- You have new mail in /var/spool/mail/root 烦不烦你(转)
转自(http://blog.csdn.net/yx_l128125/article/details/7425182) 有时在进入系统的时候经常提示You have new mail in /var/ ...
- getDrawingRect,getHitRect,getLocalVisibleRect,getGlobalVisibleRect
本文主要大体讲下getHitRect().getDrawingRect().getLocalVisibleRect().getGlobalVisibleRect. getLocationOnScree ...
- MVC中Razor视图基本语法(1)
Razor前面,必须要跟前面的有空隙,即空格(多谢一楼提醒,url里面确实不用空格,如果要在url里面只需要@(ViewBag.),加上括号就好了),之后的必须要连贯,否则加小括号 1,在页面中输出单 ...
- webapp中的日期选择
你是否在开发webapp时,选择用哪种第三方日期选择控件绞尽脑汁? 其实不用那么麻烦,现在移动端都是WebKit内核,支持HTML5,其实只要弱弱的将input中将type="date&qu ...
- mac中的xampp配置xdebug
[xdebug] zend_extension=/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20121212/ ...
- Linux-Tcp-IP
/* tcpcli.c */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include ...