hdu5023--A Corrupt Mayor's Performance Art
来源:2014 ACM/ICPC Asia Regional Guangzhou Online
题意:长度为n的一个线段,1-30为颜色代号。初始状态每个单位长度颜色都为2,然后有q次操作,P操作把区间内的颜色全部换为别的颜色,Q操作从小到大输出区间内所有的颜色代号。
线段树区间更新(裸题),一场网络赛让我学会了区间更新。
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int maxn = 1e6+10;
int n,m,seg[maxn<<2];
bool ans[35];
void push_down(int l,int r,int pos)
{
if (~seg[pos])
{
seg[pos<<1] = seg[pos<<1|1] =seg[pos];
}
seg[pos] = -1;
}
void push_up(int l,int r,int pos)
{
if (seg[pos<<1] == seg[pos<<1|1])
seg[pos] = seg[pos<<1];
else
seg[pos] = -1;
}
void update(int l,int r,int pos,int ua,int ub,int col)
{
if (ua <= l && ub >= r)
{
seg[pos] = col;
return;
}
if (~seg[pos])
push_down(l,r,pos);
int mid = (l + r) >> 1;
if (ua <= mid)
update(l,mid,pos<<1,ua,ub,col);
if (ub > mid)
update(mid+1,r,pos<<1|1,ua,ub,col);
push_up(l,r,pos);
}
void query(int l,int r,int pos,int ua,int ub)
{
if (~seg[pos])
{
ans[seg[pos]] = 1;
return;
}
int mid = (l + r) >> 1;
if (ua <= mid)
query(l,mid,pos<<1,ua,ub);
if (ub > mid)
query(mid+1,r,pos<<1|1,ua,ub);
}
int main(void)
{
#ifndef ONLINE_JUDGE
freopen ("in.txt","r",stdin);
#endif
while (scanf ("%d%d",&n,&m),n&&m)
{
update(1,n,1,1,n,2);
for (int i = 0; i < m; i++)
{
char cmd[5];
scanf ("%s",cmd);
if (cmd[0] == 'P')
{
int x,y,z;
scanf ("%d%d%d",&x,&y,&z);
update(1,n,1,x,y,z);
}
if (cmd[0] == 'Q')
{
int x,y;
scanf ("%d%d",&x,&y);
memset(ans,0,sizeof(ans));
query(1,n,1,x,y);
bool first = 0;
for (int i = 1; i <= 30; i++)
{
if (ans[i])
{
if (!first)
printf("%d",i),first = 1;
else
printf(" %d",i);
}
}
printf("\n");
}
}
}
return 0;
}
hdu5023--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 ...
- 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 线段树
A Corrupt Mayor's Performance Art Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 100000/100 ...
- A Corrupt Mayor's Performance Art(线段树区间更新+位运算,颜色段种类)
A Corrupt Mayor's Performance Art Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 100000/100 ...
- A Corrupt Mayor's Performance Art
Corrupt governors always find ways to get dirty money. Paint something, then sell the worthless pain ...
- 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 线段树区间更新+状态压缩
Link: http://acm.hdu.edu.cn/showproblem.php?pid=5023 #include <cstdio> #include <cstring&g ...
- HDU 5023 A Corrupt Mayor's Performance Art(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5023 解题报告:一面墙长度为n,有N个单元,每个单元编号从1到n,墙的初始的颜色是2,一共有30种颜色 ...
- 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 ...
随机推荐
- 【C#基础】byte二进制数组转string
//解析post请求数组返回的数组 //解码返回的二进制数组 public string DecodeBytes(byte[] c) { string html = string.Empty; try ...
- [Angular 2] Simple intro Http
To use http, we need to import the HTTP_PROVIDER, so that we can inject http to other component: imp ...
- [Falcor] Building Paths Programmatically
model.setValue('genreList[0].titles[0].rating', 5) .then(function (value) { model.get('genreList[0.. ...
- django: db - many to many
本讲介绍数据库多对多关系,代码样例继前文使用. 一,在 blog/models.py 中创建对象: # Many-To-Many Example : Authors vs Books class Au ...
- 解决Android SDK Manager下载太慢问题(转)
1.打开android sdk manager 2.打开tool->options,如图所示 3.将Proxy Settings 里的HTTP Proxy Server和HTTP Proxy P ...
- 浅谈MDX处理空值NULL及格式化结果
MDX查询结果中往往会含有"NULL"值,这是某维度下对应的的量值不存在导致的,为了让报表呈现更好的效果,在有些情况下,需要将"NULL"的切片值置换成0,这些 ...
- nginx log日志分割
@echo offrem 备份并根据时间重命名错误日志文件set "cmdstr=move E:\nginx\logs\error.log E:\nginx\logs\error%date: ...
- windows server 2003 AD
本文转载:http://www.cnblogs.com/zfanlong1314/admin/EditPosts.aspx?opt=1 今天教大家用windows server2003系统建立Acti ...
- cocos2dx Sprite的多种创建方法
1.通过文件创建 Sprite *bg = Sprite::create("backGround.jpg"); 2.通过图片的某个区域创建 SpriteFrame *frame = ...
- C#高级知识点概要(3) - 特性、自动属性、对象集合初始化器、扩展方法、Lambda表达式和Linq查询
1.特性(Attributes) 特性(Attributes),MSDN的定义是:公共语言运行时允许你添加类似关键字的描述声明,叫做attributes, 它对程序中的元素进行标注,如类型.字段.方法 ...