来源: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的更多相关文章

  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. HDU5023:A Corrupt Mayor's Performance Art(线段树区域更新+二进制)

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

  3. 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 ...

  4. A Corrupt Mayor's Performance Art(线段树区间更新+位运算,颜色段种类)

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

  5. A Corrupt Mayor's Performance Art

    Corrupt governors always find ways to get dirty money. Paint something, then sell the worthless pain ...

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

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

  7. HDU 5023 A Corrupt Mayor's Performance Art 线段树区间更新+状态压缩

    Link:  http://acm.hdu.edu.cn/showproblem.php?pid=5023 #include <cstdio> #include <cstring&g ...

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

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

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

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

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

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

随机推荐

  1. MVC 模板页和布局

    我们在以前的Asp.NET课程中已经学习过母版页了,在MVC中WebForm视图使用母版页的方法与以前基本相同. 创建一个项目MvcMasterPageDemo. 添加Home控制器,生成Index视 ...

  2. iOS 后台定位被拒注意事项

    iOS 后台定位被拒的原因很简单就是没有达到苹果对后台定位的要求. 本地要求: 1.在plist文件中添加字段 "Privacy - Location Always Usage Descri ...

  3. HTML5 API's (Application Programming Interfaces)

    New HTML5 API's (Application Programming Interfaces) The most interesting new API's are: HTML Geoloc ...

  4. uploadify3.1 参数 中文详解

    langFile: 'http://www.static-xxx.nu/uploader/uploadifyLang_en.js',//语言包的路径,能设置所有的提示文字 swf: 'http://w ...

  5. Python 文件I/O (转)

    Python 文件I/O 本章只讲述所有基本的的I/O函数,更多函数请参考Python标准文档. 打印到屏幕 最简单的输出方法是用print语句,你可以给它传递零个或多个用逗号隔开的表达式.此函数把你 ...

  6. Freemarker常用技巧(一)

    1 截取字符串有的时候我们在页面中不需要显示那么长的字符串,比如新闻标题,这样用下面的例子就可以自定义显示的长度<#if title.content?length lt 8>        ...

  7. Java初转型-Maven入门

    原系列名:Maven学习总结(一) 原博文出自于:http://www.cnblogs.com/xdp-gacl/p/3498271.html 感谢! 一.Maven的基本概念 Maven(翻译为&q ...

  8. OD: GS Bypasing via SEH / .data

    通过 SEH 绕过 GS 保护 GS 机制没对 SEH 提供保护,所以可心通过攻击异常来绕过 GS. 实验环境为: VMware : Windows sp4, 此版本无 SafeSEH 的影响 Vis ...

  9. 在Java中兼容Windows和Linux的路径处理

    Linux中的路径使用'/',而Windows下正好相反'\',Java提供了以系统属性的方式获取路径分隔符: System.getProperty("file.separator" ...

  10. (转)在Repeater中嵌套使用Repeater

    在一般的网站中浏览类别的用户控件通常都位于大多数 ASP.NET 页的左边,它使用户能够按类别快速的查找产品.最近遇到一个客户,因为在他网站上展示的产品并不多,所以要求在原有类别浏览的基础上将产品也加 ...