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)的更多相关文章

  1. POJ 3468 A Simple Problem with Integers(线段树 成段增减+区间求和)

    A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 ...

  2. HDU 3577 Fast Arrangement ( 线段树 成段更新 区间最值 区间最大覆盖次数 )

    线段树成段更新+区间最值. 注意某人的乘车区间是[a, b-1],因为他在b站就下车了. #include <cstdio> #include <cstring> #inclu ...

  3. poj 3225 Help with Intervals(线段树,区间更新)

    Help with Intervals Time Limit: 6000MS   Memory Limit: 131072K Total Submissions: 12474   Accepted:  ...

  4. POJ 3225 Help with Intervals --线段树区间操作

    题意:给你一些区间操作,让你输出最后得出的区间. 解法:区间操作的经典题,借鉴了网上的倍增算法,每次将区间乘以2,然后根据区间开闭情况做微调,这样可以有效处理开闭区间问题. 线段树维护两个值: cov ...

  5. POJ训练计划2777_Count Color(线段树/成段更新/区间染色)

    解题报告 题意: 对线段染色.询问线段区间的颜色种数. 思路: 本来直接在线段树上染色,lz标记颜色.每次查询的话訪问线段树,求出颜色种数.结果超时了,最坏的情况下,染色能够染到叶子节点. 换成存下区 ...

  6. 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 ...

  7. (中等) POJ 3225 Help with Intervals , 线段树+集合。

    Description LogLoader, Inc. is a company specialized in providing products for analyzing logs. While ...

  8. poj 3669 线段树成段更新+区间合并

    添加 lsum[ ] , rsum[ ] , msum[ ] 来记录从左到右的区间,从右到左的区间和最大的区间: #include<stdio.h> #define lson l,m,rt ...

  9. POJ 2777 Count Color (线段树成段更新+二进制思维)

    题目链接:http://poj.org/problem?id=2777 题意是有L个单位长的画板,T种颜色,O个操作.画板初始化为颜色1.操作C讲l到r单位之间的颜色变为c,操作P查询l到r单位之间的 ...

  10. poj 3468 A Simple Problem with Integers 【线段树-成段更新】

    题目:id=3468" target="_blank">poj 3468 A Simple Problem with Integers 题意:给出n个数.两种操作 ...

随机推荐

  1. Android (shape,gradient)使用总结

    设置背景色可以通过在res/drawable里定义一个xml,如下: <?xml version="1.0" encoding="utf-8"?> ...

  2. 剑指Offer - 九度1354 - 和为S的连续正数序列

    剑指Offer - 九度1354 - 和为S的连续正数序列2013-11-23 02:02 题目描述: 小明很喜欢数学,有一天他在做数学作业时,要求计算出9~16的和,他马上就写出了正确答案是100. ...

  3. 23、php知识点总结基础教程--part-1

    1.基本语法 PHP 脚本可放置于文档中的任何位置. PHP 脚本以 <?php 开头,以 ?> 结尾 <?php // 此处是 PHP 代码 ?> PHP 文件的默认文件扩展 ...

  4. Python代码书写规范

    Python 编码规范 一 代码编排1 缩进.4个空格的缩进(编辑器都可以完成此功能),不要使用Tap,更不能混合使用Tap和空格.2 每行最大长度79,换行可以使用反斜杠,最好使用圆括号.换行点要在 ...

  5. excel批量导入

    https://www.cnblogs.com/mingyue1818/p/4828865.html

  6. 设置EntityFramework中decimal类型数据精度问题(EF默认将只会保留到2为精度)

    原文:设置EntityFramework中decimal类型数据精度 EF中默认的decimal数据精度为两位数,当我们数据库设置的精度大于2时,EF将只会保留到2为精度. e.g. .19990将会 ...

  7. ubuntu16.04 使用问题笔记

    1.问题: 下列软件包有未满足的依赖关系: vim : 依赖: vim-common (= 2:7.4.826-1ubuntu1) 但是 2:7.4.1689-3ubuntu1 正要被安装 E: 无法 ...

  8. [洛谷P3701]「伪模板」主席树

    题目大意:太暴力了,就不写了,看这儿 题解:对于每个$byx$的人,从源点向人连边,容量为此人的寿命. 对于每个手气君的人,从人向汇点连边,容量为此人的寿命. 对于每个$byx$的人与手气君的人,如果 ...

  9. css实现0.5像素

    .border{ position: relative; } .border:before{ content: ''; position: absolute; width: 200%; height: ...

  10. 学习Git的一点心得以及如何把本地修改、删除的代码上传到github中

    一:学习Github的资料如下:https://git.oschina.net/progit/ 这是一个学习Git的中文网站,如果诸位能够静下心来阅读,不要求阅读太多,只需要阅读前三章,就可以掌握Gi ...