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. 解决 ld: library not found for -lPods的问题

    现在打开有pods建好的workspace文件,尝试编译,会报ld: library not found for -lPods错误,原因就是工程里面的设置项覆盖了pods中xcconfig中的设置.解 ...

  2. USACO Section1.2 Palindromic Squares 解题报告

    palsquare解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------ ...

  3. script通过script标签跨域加载数据

    /********************************************************** 说明:跨域请求数据Javascript组件 ------------------ ...

  4. dynamic基元类型与隐式类型的局部变量var

    dynamic代码示例 using System; using System.Collections.Generic; using System.Linq; using System.Text; na ...

  5. Git——1.简介

    关于版本控制 Git基础 安装Git 初始运行Git前的配置 获取帮助 关于版本控制 版本控制(VCS)是一种记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统. 本地版本控制系统 大多都 ...

  6. Linux利用OneinStack搭建环境

    OneinStack官方网站:https://oneinstack.com 介绍 OneinStack支持以下数种环境组合: LNMP(Linux + Nginx+ MySQL+ PHP) LAMP( ...

  7. [类和对象]4 C++ static & friend

    1.静态成员变量和成员函数 思考:每个变量,拥有属性.有没有一些属性,归所有对象拥有? 1.1 静态成员变量 1)定义静态成员变量 关键字 static 可以用于说明一个类的成员 静态成员提供了一个 ...

  8. 调整CodeIgniter错误报告级别

    修改位置:CI根目录 index.php 为开发环境与生产环境定义错误报告级别 if (defined('ENVIRONMENT')) { switch (ENVIRONMENT) { case 'd ...

  9. Codeforces Round #328(Div2)

    CodeForces 592A 题意:在8*8棋盘里,有黑白棋,F1选手(W棋往上-->最后至目标点:第1行)先走,F2选手(B棋往下-->最后至目标点:第8行)其次.棋子数不一定相等,F ...

  10. 用Linkedhashmap的LRU特性及SoftReference软引用构建二级缓存

    LRU: least recently used(近期最少使用算法).LinkedHashMap构造函数可以指定其迭代顺序:LinkedHashMap(int initialCapacity, flo ...