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 ...
随机推荐
- HDU 3264 Open-air shopping malls (计算几何-圆相交面积)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3264 题意:给你n个圆,坐标和半径,然后要在这n个圆的圆心画一个大圆,大圆与这n个圆相交的面积必须大于等 ...
- css3 渐变linear-gradient
background: -moz-linear-gradient(top, #FC641C, #FC761C); 参数:其共有三个参数,第一个参数表示线性渐变的方向,top 是从上到下.left 是从 ...
- (转)iOS如何取得APP的版本信息跟服务器对比进行升级提示?
关键是自动取版本信息: [NSString stringWithFormat:@"Version %@",[[NSBundle mainBundle] objectForInfoD ...
- Github 开源编辑器 ATOM 已开放下载
Update:2014-09-08 Atom 于5月6日正式开放下载(遗憾的是只有 MAC 版本),并且在 MIT 协义下开源,从界面可以看出,这款软件很像 Sublime Text,不过由于她的开源 ...
- monkeyrunner总结
device=MonkeyRunner.waitForConnection() //手机连接 result = device.takeSnapshot() //截图 result.write ...
- android怎样写一个循环文字滚动的TextView
效果图: 在layout中这样来声明: <com.kaixin001.view.ScrollText android:id="@+id/news_statustxt" and ...
- 一键注册控件的批处理(包含x86 和 x64)
@echo off if "%PROCESSOR_ARCHITECTURE%"=="x86" goto x86 if "%PROCESSOR_ARCH ...
- 使用VisualVM查看Java Heap Dump
浏览Heap Dump 可以使用VisualVM浏览heap dump文件的内容,从而快速查看在堆中分配的对象.Heap dumps在主窗口的heap dump子标签页中显示.你可以打开保存在本地的h ...
- OD: Shellcode Encoding
Shellcode 受到的限制 1. 大多数情况下 shellcode 中不允许出现 0x00 截断符,这个可以通过特殊指令来做到. 2. 有时候 shellcode 必须为可见的 ASCII 字符或 ...
- python 下的数据结构与算法---4:线形数据结构,栈,队列,双端队列,列表
目录: 前言 1:栈 1.1:栈的实现 1.2:栈的应用: 1.2.1:检验数学表达式的括号匹配 1.2.2:将十进制数转化为任意进制 1.2.3:后置表达式的生成及其计算 2:队列 2.1:队列的实 ...