(线段树)A Corrupt Mayor's Performance Art
题目链接: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的更多相关文章
- A Corrupt Mayor's Performance Art(线段树区间更新+位运算,颜色段种类)
A Corrupt Mayor's Performance Art Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 100000/100 ...
- 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 ...
- 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 ...
- 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(线段树区间更新)
题目链接: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 ...
- hdu - 5023 - A Corrupt Mayor's Performance Art(线段树)
题目原文废话太多太多太多,我就不copyandpaste到这里啦..发个链接吧题目 题目意思就是:P l r c 将区间 [l ,r]上的颜色变成c Q l r 就是打印出区间[l,r ...
- A Corrupt Mayor's Performance Art
Corrupt governors always find ways to get dirty money. Paint something, then sell the worthless pain ...
随机推荐
- google::Glog
windows下使用google的Glog库 下载glog-.tar.gz,解压. vs2013打开工程, 有四个项目 libglog libglog_static logging_unittest ...
- go-数组-切片-字典
声明一个数组变量的同时为该变量赋值. ], , } 另一种便捷方法, 类型字面量中省略代表其长度的数字 , , } 对于数组来说,索引值既不能小于0也不能大于或等于数组值的长度. 索引值的最小有效值从 ...
- JavaScript如何工作:垃圾回收机制 + 常见的4种内存泄漏
原文地址: How JavaScript works: memory management + how to handle 4 common memory leaks 本文永久链接:https://d ...
- 后缀数组(SA)
学习了LRJ神犇的代码.orz. 首先真心建议了解下基数排序!!且要有一定的c++程序经验,否则程序很难看懂. 然后对着下面的程序调试(假装你已经会了算法思想) 弄个一个礼拜一下午就能学会了. 该算法 ...
- 百万年薪python之路 -- 数据库初始
一. 数据库初始 1. 为什么要有数据库? 先来一个场景: 假设现在你已经是某大型互联网公司的高级程序员,让你写一个火车票购票系统,来hold住十一期间全国的购票需求,你怎么写? 由于在同一时 ...
- 思科Cisco 交换机 VTP负载均衡的配置
思科Cisco 交换机 VTP负载均衡的配置 3560三层交换机配置: int ran fa0/23 - fa0/24 sw trunk encapsolution dot1q sw mode tru ...
- Java基础(二十一)集合(3)List集合
一.List接口 List集合为列表类型,列表的主要特征是以线性方式存储对象. 1.实例化List集合 List接口的常用实现类有ArrayList和LinkedList,根据实际需要可以使用两种方式 ...
- 三、进程和线程、协程在python中的使用
三.进程和线程.协程在python中的使用 1.多进程一般使用multiprocessing库,来利用多核CPU,主要是用在CPU密集型的程序上,当然生产者消费者这种也可以使用.多进程的优势就是一个子 ...
- 阿里规范不建议多表Join,可这SQL要怎么写?
阿里开发手册的描述,禁止多表join: 手册上写着[强制],相信很多同学项目里面的代码都不满足这个要求. 但是关键问题是:不用join,这SQL究竟要怎么写?! 分解关联查询 即对每个要关联的表进行单 ...
- 《吊打面试官》系列-Redis基础
你知道的越多,你不知道的越多 点赞再看,养成习惯 前言 Redis在互联网技术存储方面使用如此广泛,几乎所有的后端技术面试官都要在Redis的使用和原理方面对小伙伴们进行360°的刁难.作为一个在互联 ...