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* ...
随机推荐
- [No000069]Javascript中this关键字详解
Quiz 请看下面的代码,最后alert出来的是什么呢?(chrome下按F12,选择Console直接复制粘贴运行) var name = "Bob"; var nameObj ...
- android第一行代码-2.activity基本用法
摘要: 本节主要涉及到的有activity的创建,标题栏隐藏,button绑定方法(toast的使用),menu使用,活动销毁 1.activity的创建跟注册 创建: public class Te ...
- 一份关于Swift语言学习资源的整理文件
一份关于Swift语言学习资源的整理文件 周银辉 在这里下载 https://github.com/ipader/SwiftGuide
- jquery easyui 1.4.1 API( CHM版)
ChangeLog Bug The combogrid has different height than other combo components. fixed. datagrid: The r ...
- C#进阶系列——DDD领域驱动设计初探(一):聚合
前言:又有差不多半个月没写点什么了,感觉这样很对不起自己似的.今天看到一篇博文里面写道:越是忙人越有时间写博客.呵呵,似乎有点道理,博主为了证明自己也是忙人,这不就来学习下DDD这么一个听上去高大上的 ...
- 在VS中用正则表达式查找或替换
2005VS和2008VS正则替换规则如下(2013VS不适合,不需要的同学可以直接跳到2013VS的操作办法): Example: 查找#incldue中带有gl开头的头文件的,用include.+ ...
- 【UOJ #14】【UER #1】DZY Loves Graph
http://uoj.ac/problem/14 题解很好的~ 不带路径压缩的并查集能保留树的原本形态. 按秩合并并查集可以不用路径压缩,但是因为此题要删除,如果把深度当为秩的话不好更新秩的值,所以把 ...
- Adapter的封装之路
原文:Adapter的封装之路 一.几种常见列表效果: 假如要用RecyclerView实现下面的几种效果,你会如何实现呢? 效果1:单布局效果 效果2:多布局效果 有多种Item布局 效果3 ...
- USB Keyboard Recorder
catalogue . 引言 . Device Class Definition for Human Interface Devices (HID) . USB HID Report Descript ...
- JS 验证数组中是否包含重复元素
验证JS中是否包含重复元素,有重复返回true:否则返回false 方案一. function isRepeat(data) { var hash = {}; for (var i in data) ...