HDU 5023 A Corrupt Mayor's Performance Art 线段树区间更新+状态压缩
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 线段树区间更新+状态压缩的更多相关文章
- 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 ...
- 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 ...
- HDU5023:A Corrupt Mayor's Performance Art(线段树区域更新+二进制)
http://acm.hdu.edu.cn/showproblem.php?pid=5023 Problem Description Corrupt governors always find way ...
- HDU 5023 A Corrupt Mayor's Performance Art(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5023 解题报告:一面墙长度为n,有N个单元,每个单元编号从1到n,墙的初始的颜色是2,一共有30种颜色 ...
- ACM学习历程—HDU 5023 A Corrupt Mayor's Performance Art(广州赛区网赛)(线段树)
Problem Description Corrupt governors always find ways to get dirty money. Paint something, then sel ...
- HDU 5023 A Corrupt Mayor's Performance Art (据说是线段树)
题意:给定一个1-n的墙,然后有两种操作,一种是P l ,r, a 把l-r的墙都染成a这种颜色,另一种是 Q l, r 表示,输出 l-r 区间内的颜色. 析:应该是一个线段树+状态压缩,但是我用s ...
- 2014 网选 广州赛区 hdu 5023 A Corrupt Mayor's Performance Art
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #d ...
- hdu - 5023 - A Corrupt Mayor's Performance Art(线段树)
题目原文废话太多太多太多,我就不copyandpaste到这里啦..发个链接吧题目 题目意思就是:P l r c 将区间 [l ,r]上的颜色变成c Q l r 就是打印出区间[l,r ...
- hdu 5023 线段树延迟更新+状态压缩
/* 线段树延迟更新+状态压缩 */ #include<stdio.h> #define N 1100000 struct node { int x,y,yanchi,sum; }a[N* ...
随机推荐
- 解决win10卡顿现象
前两天打开了windows defender,想着既然是window自带的防护工具,应该效果不错.经过测试之后 ,发现这个要占用很大内存,得不偿失.如果想要保证系统安全,甚至腾讯电脑管家做的都比这个w ...
- js中的hasOwnProperty和isPrototypeOf方法
hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象.不过需要注意的是,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员. isPrototypeO ...
- jQuery ScrollPagination修改之后
jQuery ScrollPagination修改之后代码 /* ** Anderson Ferminiano ** contato@andersonferminiano.com -- feel fr ...
- ACE admin 后台管理框架
一.样式 1.常见按钮 .btn-app .btn-group .btn-corner .btn-xs .btn-sm .btn-mini .btn-minier .btn-defalut .btn ...
- XML中输入特殊符号
XML中输入特殊符号 周银辉 特殊符号比如 ™, 要在xml中使用的话, 其实和html的转码是一样的, 参考下面这个表(使用十进制编码那一列) 特殊符号 命名实体 十进制编码 特殊符号 命名实体 十 ...
- bash shell
Linux的shell 与windows只有一种批处理脚本不同,由于早年的Unix年代,发展者众,出现了各种不同的distribution,因此也随着不同的distribution出现了各自的shel ...
- JS组件系列——Bootstrap Select2组件使用小结
前言:在介绍select组件的时候,博主之前分享过一篇JS组件系列——两种bootstrap multiselect组件大比拼,这两个组件的功能确实很强大,只可惜没有图文结合的效果(也就是将图片放入到 ...
- Winform开发:在ProgressBar显示百分比数字
如果不使用Label而是直接在进度条上显示文字,可以扩展一个派生类自己画,代码如下: public partial class Form1 : Form { public Form1() { Init ...
- 1201MySQL配置文件mysql.ini参数详解
转自http://www.cnblogs.com/feichexia/archive/2012/11/27/mysqlconf.html my.ini(Linux系统下是my.cnf),当mysql服 ...
- MVC架构模式分析与设计(一)---简单的mvc架构
首先 我要感谢慕课网的老师提供视频资料 http://www.imooc.com/learn/69 下面我来进行笔记 我们制作一个简单的mvc架构 制作第一个控制器 testController.cl ...