POJ 3225.Help with Intervals-线段树(成段替换、区间异或、简单hash)
POJ3225.Help with Intervals
这个题就是对区间的各种操作,感觉这道题写的一点意思都没有,写到后面都不想写了,而且更神奇的是,自己的编译器连结果都输不出来,但是交上就过了,也是令人头大的操作,这题没意思,不要写了。我写到后面就写不下去了,直接去看了别人的代码。。。
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<cctype>
using namespace std;
typedef long long ll;
const int maxn=;
const int inf=0x3f3f3f3f;
const double eps=1e-;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 int col[maxn<<],Xor[maxn<<],hash[maxn<<]; void fxor(int rt)
{
if(col[rt]!=-)col[rt]^=;
else Xor[rt]^=;
}
void pushdown(int rt)
{
if(col[rt]!=-){
col[rt<<]=col[rt<<|]=col[rt];
Xor[rt<<]=Xor[rt<<|]=;
col[rt]=-;
}
if(Xor[rt]){
fxor(rt<<);
fxor(rt<<|);
Xor[rt]=;
}
}
void update(char op,int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R){
if(op=='U'){
col[rt]=;
Xor[rt]=;
}
else if(op=='D'){
col[rt]=;
Xor[rt]=;
}
else if(op=='C'||op=='S'){
fxor(rt);
}
return ;
} pushdown(rt);
int m=(l+r)>>;
if(L<=m)update(op,L,R,lson);
else if(op=='I'||op=='C'){
Xor[rt<<]=col[rt<<]=;
}
if(R> m)update(op,L,R,rson);
else if(op=='I'||op=='C'){
Xor[rt<<|]=col[rt<<|]=;
}
}
void query(int l,int r,int rt)
{
if(col[rt]==){
for(int i=l;i<=r;i++){
hash[i]=;
}
return ;
}
else if(col[rt]==)return ;
if(l==r) return ; pushdown(rt);
int m=(l+r)>>;
query(lson);
query(rson);
}
int main()
{
col[]=Xor[]=;
char op,l,r;
int a,b;
while(~scanf("%c %c%d,%d%c\n",&op,&l,&a,&b,&r)){
a<<=,b<<=;
if(l=='(')a++;
if(r==')')b--;
if(a>b){
if(op=='C'||op=='I'){
col[]=Xor[]=;
}
}
else
update(op,a,b,,maxn,);
}
query(,maxn,);
int flag=;
int s=-,e;
for(int i=;i<=maxn;i++){
if(hash[i]){
if(s==-)s=i;
e=i;
}
else{
if(s!=-){
if(flag)printf(" ");
flag=;
printf("%c%d,%d%c",s&?'(':'[',s>>,(e+)>>,e&?')':']');
s=-;
}
}
}
if(!flag)printf("empty set");
puts("");
return ;
}
5道题解完成,感觉后面再写题就应该是要用脑子来写了,水题水一下就可以了,就这样吧,下次再集齐5道再来写线段树可真有意思呢续集(3)。
滚了滚了。。。
POJ 3225.Help with Intervals-线段树(成段替换、区间异或、简单hash)的更多相关文章
- POJ 3468 A Simple Problem with Integers(线段树 成段增减+区间求和)
A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 ...
- HDU 3577 Fast Arrangement ( 线段树 成段更新 区间最值 区间最大覆盖次数 )
线段树成段更新+区间最值. 注意某人的乘车区间是[a, b-1],因为他在b站就下车了. #include <cstdio> #include <cstring> #inclu ...
- poj 3225 Help with Intervals(线段树,区间更新)
Help with Intervals Time Limit: 6000MS Memory Limit: 131072K Total Submissions: 12474 Accepted: ...
- POJ 3225 Help with Intervals --线段树区间操作
题意:给你一些区间操作,让你输出最后得出的区间. 解法:区间操作的经典题,借鉴了网上的倍增算法,每次将区间乘以2,然后根据区间开闭情况做微调,这样可以有效处理开闭区间问题. 线段树维护两个值: cov ...
- POJ训练计划2777_Count Color(线段树/成段更新/区间染色)
解题报告 题意: 对线段染色.询问线段区间的颜色种数. 思路: 本来直接在线段树上染色,lz标记颜色.每次查询的话訪问线段树,求出颜色种数.结果超时了,最坏的情况下,染色能够染到叶子节点. 换成存下区 ...
- poj 3468 线段树 成段增减 区间求和
题意:Q是询问区间和,C是在区间内每个节点加上一个值 Sample Input 10 51 2 3 4 5 6 7 8 9 10Q 4 4Q 1 10Q 2 4C 3 6 3Q 2 4Sample O ...
- (中等) POJ 3225 Help with Intervals , 线段树+集合。
Description LogLoader, Inc. is a company specialized in providing products for analyzing logs. While ...
- poj 3669 线段树成段更新+区间合并
添加 lsum[ ] , rsum[ ] , msum[ ] 来记录从左到右的区间,从右到左的区间和最大的区间: #include<stdio.h> #define lson l,m,rt ...
- POJ 2777 Count Color (线段树成段更新+二进制思维)
题目链接:http://poj.org/problem?id=2777 题意是有L个单位长的画板,T种颜色,O个操作.画板初始化为颜色1.操作C讲l到r单位之间的颜色变为c,操作P查询l到r单位之间的 ...
- poj 3468 A Simple Problem with Integers 【线段树-成段更新】
题目:id=3468" target="_blank">poj 3468 A Simple Problem with Integers 题意:给出n个数.两种操作 ...
随机推荐
- NSThread那些事儿
NSThread 哎呀,它面向对象,再去看看苹果提供的API,对比一下Pthreads,简单明了,人生仿佛又充满了阳光和希望,我们先来一看一下系统提供给我们的API自然就知道怎么用了,来来来,我给你注 ...
- SDK接入注意点
1. 新建的android项目,要把MainActivity.java里生成的东西全部删去,最好只留个onCreate入口方法,不然会产生什么“hello world”,会把自己写的View内的东西覆 ...
- java 继承小结
[code=java] //多态的经典例子 //向上转型后,父类只能调用子类和父类的共同方法和的重写方法(方法名相同,参数也相同),不能调用重载方法(方法名相同,但参数不同) class A { pu ...
- 对于进程没杀死占用内存和cpu行为的方法
在跑机器学习或者深度学习的过程中有可能遇到没杀死进程的情况,但是程序的入口又没关掉,尤其是我使用jupyter从远程Linux映射到windows浏览器跑程序的时候 对于上面的问题, 首先运行 hto ...
- [bzoj3456] 城市规划 [递推+多项式求逆]
题面 bzoj权限题面 离线题面 思路 orz Miskcoo ! 先考虑怎么算这个图的数量 设$f(i)$表示$i$个点的联通有标号无向图个数,$g(i)$表示$n$个点的有标号无向图个数(可以不连 ...
- 【BZOJ 4151 The Cave】
Time Limit: 5 Sec Memory Limit: 256 MBSec Special JudgeSubmit: 293 Solved: 144[Submit][Status][Di ...
- (转)myeclipse工程 junit不能运行 ClassNotFoundException
博文转自:http://www.cnblogs.com/java-zone/articles/2730722.html myeclipse工程 junit不能运行 1 2 3 4 5 6 7 8 ...
- error : cannot open source file "SDKDDKVer.h"
属性->VC++ Directions-> include path 中加了:$(IncludePath) library path 中加了:$(LibraryPath)
- bzoj1264 [AHOI2006]基因匹配Match 树状数组+lcs
1264: [AHOI2006]基因匹配Match Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1255 Solved: 835[Submit][ ...
- Windows 2008 R2无法打补丁
遇到了Windows 2008 R2无法打补丁,并且控制台上的feature和roles都是error 可下载这个补丁进行修复: System Update Readiness Tool for Wi ...