来源: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. JAVA 面试整理,面试汇总

    1.JAVA是通过重写和重载来实现多态性的. 重写:同样的方法签名,不同的方法实现 重载:同样的方法名,不同的参数类型或参数个数 2.JAVA中如果存在不再使用的对象,但是程序又持有该对象的引用,就会 ...

  2. 读取xml到DataSet中去

    XML如下: <?xml version="1.0" encoding="utf-8" ?> <Config> <System&g ...

  3. ReactJS 的背景及原理

    原文链接:http://www.infoq.com/cn/articles/subversion-front-end-ui-development-framework-react 在Web开发中,我们 ...

  4. Lance老师UI系列教程第八课->新浪新闻SlidingMenu界面的实现

    UI系列教程第八课:Lance老师UI系列教程第八课->新浪新闻SlidingMenu界面的实现 今天蓝老师要讲的是关于新浪新闻侧滑界面的实现.先看看原图: 如图所示,这种侧滑效果以另一种方式替 ...

  5. Android两种 旋转Bitmap方法

    方法1. 利用Bitmap.createBitmap Bitmap adjustPhotoRotation(Bitmap bm, final int orientationDegree) {      ...

  6. python字符串连接方式(转)

    在python中有很多字符串连接方式,今天就在这里具体总结一下: ①.最原始的字符串连接方式:str1 + str2②.python 新字符串连接语法:str1, str2③.奇怪的字符串方式:str ...

  7. 图形混合模式 PorterDuff Xfermodes

    16种图形混合模式示例 首先绘制Dst(黄色的),然后绘制Src(蓝色的) 问题来了:为何还会有部分黄色?不应该是把src和dst都清除了吗? 图形混合模式简介 ProterDuff的含义 Prote ...

  8. c - 输出 101 至 200之间的素数.

    #include <stdio.h> #include <math.h> //判断 101-200 之间有多少个素数,并输出所有素数. int main(void) { , e ...

  9. Sed命令学习

    1.Sed简介     流数据编辑器 Stream editer(sed),它是一种行编辑器(对应于全屏编辑器),一次处理一行的内容.默认不编辑原文件内容(-i会直接修改原文件).处理时,它先将当前符 ...

  10. JQuery获取当前屏幕的高度宽度

    JQuery获取浏览器窗口宽高,文档宽高的代码,使用jquery的朋友可以参考下. <script type="text/javascript"> $(document ...