Link:  http://acm.hdu.edu.cn/showproblem.php?pid=5023

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef __int64 LL;
typedef unsigned int UINT;
const int maxn = 1e6 + ; #define LEFT(a,b) ((a) << (b))
#define RIGHT(a,b) ((a) >> (b)) struct node
{
UINT c,num;
int l,r;
node() {}
node(const int t_l,const int t_r,const UINT t_c,const UINT t_num)
{
l = t_l,r = t_r;
c = ( << (t_c - ));
num = t_num;
}
}tree[*maxn]; void Init(const int p)
{
if(tree[p].l == tree[p].r) return ;
int mid = RIGHT(tree[p].l + tree[p].r,);
tree[LEFT(p,)] = node(tree[p].l,mid,,);
tree[LEFT(p,)+] = node(mid+,tree[p].r,,);
Init(LEFT(p,));
Init(LEFT(p,)+);
}
void paste(const int p,const int t_l,const int t_r,const UINT t_c)
{
if(t_l > t_r) return ;
if(t_l == tree[p].l && t_r == tree[p].r)
{
tree[p].c = t_c;
tree[p].num = ;
return ;
}
int mid = (tree[p].l + tree[p].r) / ;
/*
如果该段区间只有一种颜色,则要先把该段区间里的目标区间意外的区间涂成原来的颜色
*/
if( == tree[p].num)
{
paste(LEFT(p,),tree[p].l,mid,tree[p].c);
paste(LEFT(p,)+,mid+,tree[p].r,tree[p].c);
/*
if(t_r <= mid) paste(LEFT(p,1)+1,mid+1,tree[p].r,tree[p].c);
else if(t_l <= mid && t_r > mid)
{
paste(LEFT(p,1),tree[p].l,t_l-1,tree[p].c);
paste(LEFT(p,1)+1,t_r+1,tree[p].r,tree[p].c);
}
else if(t_l > mid) paste(LEFT(p,1),tree[p].l,mid,tree[p].c);
*/
}
if(t_r <= mid) paste(LEFT(p,),t_l,t_r,t_c);
else if(t_l <= mid && t_r > mid)
{
paste(LEFT(p,),t_l,mid,t_c);
paste(LEFT(p,)+,mid+,t_r,t_c);
}
else if(t_l > mid) paste(LEFT(p,)+,t_l,t_r,t_c); tree[p].c = tree[LEFT(p,)].c | tree[LEFT(p,)+].c;
tree[p].num = ;
for(int i = ;i <= ;i++)
if(tree[p].c & ( << i))
tree[p].num++;
} void quire(const int p,const int t_l,const int t_r,UINT& t_c)
{
if( == tree[p].num || (tree[p].l == t_l && tree[p].r == t_r))
{
t_c |= tree[p].c;
return ;
}
int mid = (tree[p].l + tree[p].r) / ;
if(t_r <= mid) quire(LEFT(p,),t_l,t_r,t_c);
else if(t_l <= mid && t_r > mid)
{
quire(LEFT(p,),t_l,mid,t_c);
quire(LEFT(p,)+,mid+,t_r,t_c);
}
else if(t_l > mid) quire(LEFT(p,)+,t_l,t_r,t_c);
}
void print()
{
for(int i = ;i <= ;++i)
printf("%d ",tree[i].c);
puts("");
for(int i = ;i <= ;i++)
printf("%d ",tree[i].num);
puts("");
}
int main()
{
// freopen("in.txt","r",stdin);
int n,m;
while(scanf("%d%d",&n,&m),m+n)
{
tree[] = node(,n,,);
Init();
char oper[];
while(m--)
{
scanf("%s",oper);
if('P' == oper[])
{
int x,y,c;
scanf("%d%d%d",&x,&y,&c);
paste(,x,y, << (c - ));
// print();
}
else
{
int x,y;
UINT t_c = ;
scanf("%d%d",&x,&y);
quire(,x,y,t_c);
bool flag = false;
for(int i = ;i <= ;++i)
if(t_c & ( << i))
{
if(flag) printf(" ");
flag = true;
printf("%d",i+);
}
if(flag) puts("");
// print();
}
}
}
return ;
}

HDU 5023 A Corrupt Mayor's Performance Art 线段树区间更新+状态压缩的更多相关文章

  1. hdu 5023 A Corrupt Mayor's Performance Art 线段树

    A Corrupt Mayor's Performance Art Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 100000/100 ...

  2. hdu----(5023)A Corrupt Mayor's Performance Art(线段树区间更新以及区间查询)

    A Corrupt Mayor's Performance Art Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 100000/100 ...

  3. HDU5023:A Corrupt Mayor's Performance Art(线段树区域更新+二进制)

    http://acm.hdu.edu.cn/showproblem.php?pid=5023 Problem Description Corrupt governors always find way ...

  4. HDU 5023 A Corrupt Mayor's Performance Art(线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5023 解题报告:一面墙长度为n,有N个单元,每个单元编号从1到n,墙的初始的颜色是2,一共有30种颜色 ...

  5. ACM学习历程—HDU 5023 A Corrupt Mayor's Performance Art(广州赛区网赛)(线段树)

    Problem Description Corrupt governors always find ways to get dirty money. Paint something, then sel ...

  6. HDU 5023 A Corrupt Mayor's Performance Art (据说是线段树)

    题意:给定一个1-n的墙,然后有两种操作,一种是P l ,r, a 把l-r的墙都染成a这种颜色,另一种是 Q l, r 表示,输出 l-r 区间内的颜色. 析:应该是一个线段树+状态压缩,但是我用s ...

  7. 2014 网选 广州赛区 hdu 5023 A Corrupt Mayor's Performance Art

    #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #d ...

  8. hdu - 5023 - A Corrupt Mayor's Performance Art(线段树)

    题目原文废话太多太多太多,我就不copyandpaste到这里啦..发个链接吧题目 题目意思就是:P  l  r  c  将区间 [l ,r]上的颜色变成c    Q  l r 就是打印出区间[l,r ...

  9. hdu 5023 线段树延迟更新+状态压缩

    /* 线段树延迟更新+状态压缩 */ #include<stdio.h> #define N 1100000 struct node { int x,y,yanchi,sum; }a[N* ...

随机推荐

  1. 2.一个EJB的小Demo

    新建一个java普通项目即可 这里用到了Jboss,需要安装Jboss,然后进入jboss-4.2.3.GA\client目录,拷贝所有的jar包到本项目的lib下. 3个接口分别如下所示: publ ...

  2. python基础之编码问题

    python基础之编码问题 本节内容 字符串编码问题由来 字符串编码解决方案 1.字符串编码问题由来 由于字符串编码是从ascii--->unicode--->utf-8(utf-16和u ...

  3. LoadLibrary加载动态库失败的解决办法

    from:http://blog.sina.com.cn/s/blog_62ad1b8101017qub.html 若DLL不在调用方的同一目录下,可以用LoadLibrary(L"DLL绝 ...

  4. Linux下部署docker记录(1)-Volume使用

    之前部署了Linux下部署docker记录(0)-基础环境安装,接下来看看Docker Volume的使用. Docker volume使用1)一个数据卷是一个特别指定的目录,该目录利用容器的UFS文 ...

  5. 上海闪酷成为京东商城第一批独立软件开发商(ISV)

    闪酷信息技术(上海)有限公司一直致力于为品牌企业提供电子商务软件及其服务,为其拓展电商渠道保驾护航.上海闪酷依据多年的行业经验和技术积累,与中国 最大的B2C商城达成战略合作,为其2万多家品牌供应商提 ...

  6. 软件工程导论-目录-K-T+RJ大

    目录 10 第1章 软件工程学概述/1 19 1.1 软件危机/1 19 1.1.1 软件危机的介绍/1 19 1.1.2 产生软件危机的原因/3 21 1.1.3 消除软件危机的途径/4 22 1. ...

  7. 在CentOS 6.4 x86_32中使用Rhythmbox听MP3

    Linux中的Rhythmbox音乐播放器,是没有自带MP3音乐解码器的,所以必须得自行安装相应的音乐或视频解码器.好了,不废话…… # cd /tmp # wget http://dl.atrpms ...

  8. Androidstudio安装AVD出现no system images installed for this target解决方案

    解决方案:

  9. Linux命令 -- 查看系统版本的各种方法

    适用于CentOS

  10. 分享我的开源项目-springmore

    之前有在博客园分享过springmore,不知道是什么原因,被管理员移除首页 在此郑重声明,这是我个人的开源项目,东西不多,也不存在打广告,也没有什么利益可图 完全是出于分享的目的,望博客园管理员予以 ...