题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5023

题意: 区间更新, 区间询问;

题解: 区间更新, 区间询问, 一共30种颜色, 可用int 来存。

地区选拔赛的一道题,当时还没怎么学线段树(只会单点更新), 这道题只能看着别人A, 自己干着急。  今天刚看了NOS神牛的第一道区间更新就迫不及待的尝试了下。

不得不说, 题目水, 人更水TT。

最后在感慨一下, NOS神牛的代码真tm好看。

 /***Good Luck***/
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <functional>
#include <cmath>
#include <numeric> #define Zero(a) memset(a, 0, sizeof(a))
#define Neg(a) memset(a, -1, sizeof(a))
#define All(a) a.begin(), a.end()
#define PB push_back
#define inf 0x3f3f3f3f
#define inf2 0x7fffffffffffffff
#define ll long long
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")
void get_val(int &a) {
int value = , s = ;
char c;
while ((c = getchar()) == ' ' || c == '\n');
if (c == '-') s = -s; else value = c - ;
while ((c = getchar()) >= '' && c <= '')
value = value * + c - ;
a = s * value;
}
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1| 1
const int maxn = 1e6 + ;
int A[maxn << ];
int n, m;
int col[maxn << ];
void pu(int rt) {
A[rt] = A[rt << ] | A[rt << | ];
} void pd(int rt) {
if (col[rt]) {
col[rt << ] = col[rt << | ] = col[rt];
A[rt << ] = col[rt];
A[rt << | ] = col[rt];
col[rt] = ;
}
} void update(int L, int R, int v, int l, int r, int rt) {
if (L <= l && r <= R) {
A[rt] = << (v - );
col[rt] = << (v - );
return;
}
pd(rt);
int m = (l + r) >> ;
if (L <= m) update(L, R, v, lson);
if (R > m) update(L, R, v, rson);
pu(rt);
} int query(int L, int R, int l, int r, int rt) {
if (L <= l && r <= R) {
return A[rt];
}
pd(rt);
int m = (l + r) >> ;
int ret = ;
if (L <= m) ret |= query(L, R, lson);
if (R > m) ret |= query(L, R, rson);
return ret;
}
int main() {
//freopen("data.out", "w", stdout);
//freopen("data.in", "r", stdin);
//cin.sync_with_stdio(false);
while (scanf("%d%d", &n, &m), n|m) {
int t = n << ;
char q[];
int a, b, v, ans;
for (int i = ; i <= t; ++i) {
A[i] = ;
col[i] = ;
}
vector<int> vr;
for (int i = ; i <= m; ++i) {
scanf("%s", q);
if (q[] == 'P') {
scanf("%d%d%d", &a, &b, &v);
update(a, b,v, , n, );
} else {
scanf("%d%d", &a, &b);
ans = query(a, b, , n, );
for (int w = ; w <= ; ++w) {
if (ans & ) vr.push_back(w );
ans >>= ;
}
for (int w = ; w < vr.size(); ++w) printf("%d ", vr[w - ]);
printf("%d\n", *vr.rbegin());
vr.clear();
}
}
}
return ;
}

(线段树)A Corrupt Mayor's Performance Art的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

  8. hdu - 5023 - A Corrupt Mayor's Performance Art(线段树)

    题目原文废话太多太多太多,我就不copyandpaste到这里啦..发个链接吧题目 题目意思就是:P  l  r  c  将区间 [l ,r]上的颜色变成c    Q  l r 就是打印出区间[l,r ...

  9. A Corrupt Mayor's Performance Art

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

随机推荐

  1. VS2017-Linux项目-使用第三方库如何配置

    1.虚拟机Ubuntu 16.04,安装第三方库,perftools::tcmalloc. 2.Win10下vs2017创建linux项目. 3.项目>>属性>>VC++ 目录 ...

  2. vue css 深度选择器

    在我们想穿透的选择器前边添加 >>> 或者 /deep/ 或者 ::v-deep. 官方地址:https://vue-loader.vuejs.org/guide/scoped-cs ...

  3. PHP spl_autoload和class_exsits使用技能

    本文章的PHP使用版本:5.4.7 PHP建议使用: spl_autoload_register 那么写了一种实现 文件路径 core core.php ChildrenClass.php Paren ...

  4. 总结Java equals()和hashCode()的联系

    Java equals()和hashCode()的联系 如果两个对象是相等的,那么它们必须有相同的哈希码. 如果两个对象具有相同的哈希码,他们可能相等,可能不相等. 如果两个对象是不同的类的实例 他们 ...

  5. go map数据结构和源码详解

    目录 1. 前言 2. go map的数据结构 2.1 核心结体体 2.2 数据结构图 3. go map的常用操作 3.1 创建 3.2 插入或更新 3.3 删除 3.4 查找 3.5 range迭 ...

  6. 路由器配置深入浅出—路由器接口PPP协议封装及PAP和CHAP验证配置

    知识域: 是针对点对点专线连接的接口的二层封装协议配置 PPP的PAP和CHAP验证,cpt支持,不一定要在gns3上做实验. 路由器出厂默认是hdlc封装,修改为ppp封装后,可以采用pap验证或者 ...

  7. leetcode算法小题(2)

    题目描述: 给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. package Simple;import java.util.Scanner;public class Prac ...

  8. Nexus 上传项目到私服

    1. maven setting配置 <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed ...

  9. os模块操作文件

    os模块: path=os.path.join(os.path.dirname(os.path.dirname(__file__)),'images') path:运行脚本的当前文件下的上一个文件的地 ...

  10. DZY Loves Math II:多重背包dp+组合数

    Description Input 第一行,两个正整数 S 和 q,q 表示询问数量.接下来 q 行,每行一个正整数 n. Output 输出共 q 行,分别为每个询问的答案. Sample Inpu ...