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. JavaScript简易学习笔记

    学习地址:http://www.w3school.com.cn/js/index.asp 文字版: https://github.com/songzhenhua/github/blob/master/ ...

  2. a链接点击下载图片到本地(php)

    $url="http://pan.baidu.com/share/qrcode?w=150&h=150&url=http://gandao.my".U('Quest ...

  3. Linux开启MySQL远程连接

    Linux开启MySQL远程连接的设置步骤 . MySQL默认root用户只能本地访问,不能远程连接管理MySQL数据库,那么Linux下如何开启MySQL远程连接?设置步骤如下: 1.GRANT命令 ...

  4. [译]如何禁止Requests库的log日志信息呢?

    原文来源: https://stackoverflow.com/questions/11029717/how-do-i-disable-log-messages-from-the-requests-l ...

  5. Android记事本开发04

    昨天: 显式intent 隐身intent 今天: intentFilter 问题: 无法直接预览布局文件的效果.

  6. linux sed讲解

    1.sed 查找替换 显示某一行或某几行##替换sed 's###g' oldboy.txtsed 's@@@g' oldboy.txt sed -i 's###g' oldboy.txtsed -i ...

  7. sqlserver 汉字转拼音 索引 函数

    IF OBJECT_ID('[fn_GetPinyin]') IS NOT NULL DROP FUNCTION [fn_GetPinyin] GO create function [dbo].[fn ...

  8. poj 2253 Frogger (最短路径)

    Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22557   Accepted: 7339 Descript ...

  9. 洛谷 P2329 [SCOI2005]栅栏 解题报告

    P2329 [SCOI2005]栅栏 题目描述 农夫约翰打算建立一个栅栏将他的牧场给围起来,因此他需要一些特定规格的木材.于是农夫约翰到木材店购买木材.可是木材店老板说他这里只剩下少部分大规格的木板了 ...

  10. 2017-7-18-每日博客-关于Linux基本命令CnetOS7系统基本操作命令.doc

    1.root/下 cat  anaconda-ks.cfg 确定是否装base软件组 yum groupinstall base  安装base组ifconfig 命令就可以使用了或者使用ip add ...