HDU 5023 A Corrupt Mayor's Performance Art (据说是线段树)
题意:给定一个1-n的墙,然后有两种操作,一种是P l ,r, a 把l-r的墙都染成a这种颜色,另一种是 Q l, r 表示,输出 l-r 区间内的颜色。
析:应该是一个线段树+状态压缩,但是我用set暴力过去了。用线段树+状态压缩,区间更新,很简单,就不说了。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 100 + 5;
const int mod = 1e9 + 7;
const int dr[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
struct Node{
int l, r;
Node() { }
Node(int ll, int rr) : l(ll), r(rr) { }
bool operator < (const Node &p) const{
return r < p.r;
}
};
set<Node> sets[35];
set<Node> :: iterator it, it1; int main(){
while(scanf("%d %d", &n, &m) == 2){
if(!m && !n) break;
for(int i = 1; i <= 30; ++i) sets[i].clear();
sets[2].insert(Node(1, n));
char s[5];
int a, b, c;
Node u;
while(m--){
scanf("%s", s);
if(s[0] == 'P'){
scanf("%d %d %d", &a, &b, &c);
for(int i = 1; i <= 30; ++i){
if(sets[i].size() == 0) continue;
while(true){
it1 = sets[i].lower_bound(Node(0, a));
if(it1 == sets[i].end() || it1->l > b) break;
u = *it1;
sets[i].erase(it1);
if(u.l < a){
sets[i].insert(Node(u.l, a-1));
if(u.r > b) sets[i].insert(Node(b+1, u.r));
}
else if(u.r > b) sets[i].insert(Node(b+1, u.r));
}
}
sets[c].insert(Node(a, b));
}
else{
scanf("%d %d", &a, &b);
int cnt = 0;
for(int i = 1; i < 31; ++i){
if(sets[i].size() == 0) continue;
it1 = sets[i].lower_bound(Node(0, a));
if(it1 == sets[i].end() || it1->l > b) continue;
if(cnt) putchar(' ');
printf("%d", i);
++cnt;
}
putchar('\n');
}
}
}
return 0;
}
线段树:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
const int dr[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
LL sum[maxn<<2], sets[maxn<<2]; void pushup(int rt){
sum[rt] = sum[rt<<1] | sum[rt<<1|1];
} void pushdown(int rt, int len){
int l = rt<<1, r = rt<<1|1;
if(sets[rt]){
sum[r] = sum[l] = sets[rt];
sets[l] = sets[r] = sets[rt];
sets[rt] = 0;
}
} void build(int l, int r, int rt){
sets[rt] = 0;
if(l == r){
sum[rt] = 2;
return ;
}
int m = (l + r) >> 1;
build(lson);
build(rson);
pushup(rt);
} void update(int L, int R, int val, int l, int r, int rt){
if(L <= l && R >= r){
sets[rt] = 1<<val-1;
sum[rt] = 1<<val-1;
return ;
}
pushdown(rt, r-l+1);
int m = (l + r) >> 1;
if(L <= m) update(L, R, val, lson);
if(R > m) update(L, R, val, rson);
pushup(rt);
} LL query(int L, int R, int l, int r, int rt){
if(L <= l && R >= r) return sum[rt];
pushdown(rt, r-l+1);
LL ans = 0;
int m = (l + r) >> 1;
if(L <= m) ans |= query(L, R, lson);
if(m < R) ans |= query(L, R, rson);
return ans;
} int main(){
while(scanf("%d %d", &n, &m) == 2 && m+n){
build(1, n, 1);
int l, r, val;
char s[5];
while(m--){
scanf("%s", s);
if(s[0] == 'P'){
scanf("%d %d %d", &l, &r, &val);
update(l, r, val, 1, n, 1);
}
else{
scanf("%d %d", &l, &r);
LL ans = query(l, r, 1, n, 1);
int cnt = 0;
for(int i = 0; i < 30; ++i) if(ans & (1<<i)){
if(cnt) putchar(' ');
printf("%d", i+1);
++cnt;
}
printf("\n");
}
}
}
return 0;
}
HDU 5023 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 ...
- 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 线段树区间更新+状态压缩
Link: http://acm.hdu.edu.cn/showproblem.php?pid=5023 #include <cstdio> #include <cstring&g ...
- 2014 网选 广州赛区 hdu 5023 A Corrupt Mayor's Performance Art
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #d ...
- hdu - 5023 - A Corrupt Mayor's Performance Art(线段树)
题目原文废话太多太多太多,我就不copyandpaste到这里啦..发个链接吧题目 题目意思就是:P l r c 将区间 [l ,r]上的颜色变成c Q l r 就是打印出区间[l,r ...
- 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 ...
- HDU5023:A Corrupt Mayor's Performance Art(线段树区域更新+二进制)
http://acm.hdu.edu.cn/showproblem.php?pid=5023 Problem Description Corrupt governors always find way ...
随机推荐
- POJ 3142 The Balance
Description Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of ...
- CGContextAddArcToPoint和CGContextAddArc
比较难的是CGContextAddArcToPoint 代码如下: CGContextRef context=UIGraphicsGetCurrentContext(); CGContextSetRG ...
- archlinux 内核编译笔记
# cp linux-3.10.5.tar.gz /usr/src/linux-3.10.5.tar.gz# cd /usr/src# tar xvzf linux-3.10.5.tar.gz lin ...
- Windows、VS 与 .net
原文地址:https://msdn.microsoft.com/en-us/library/bb822049(v=vs.110).aspx .NET Framework version CLR ver ...
- jquery 选择器汇总
jQueryAPI_1.7.1_CN.chm下载地址http://download.csdn.net/detail/zhai123_/6459563 jquery 选择器大体上可分为4 类: 1.基本 ...
- python与正则表达式:re模块详解
re模块是python中处理正在表达式的一个模块 正则表达式知识储备:http://www.cnblogs.com/huamingao/p/6031411.html 1. match(pattern, ...
- Fliwer:监控植物状态 实现远程浇水
Fliwer是一款针对植物而研发出来的设备,可以监控土壤水分.光照.温度.空气湿度和肥料是否充足这些指标.结合云端的植物数据和天气预报,它能够自动决定什么时候给植物浇水,甚至提醒你什么时候应该施肥.修 ...
- Device Path in WinPrefetchView
As we know that the Prefetch file is used for optimizing the loading time of the application in the ...
- java 标识符命名规则
标识符:就是给类,接口,方法,变量等起名字. 组成规则: A:英文字母大小写 B:数字字符 C:$和_ 注意事项: A:不能以数字开头 B:不能是Java中的关键字 C:Java语言严格区分大小写 包 ...
- oracle 认证方式
Oracle登录的时候有两种认证方式,一种是“操作系统认证”,一种是“口令文件认证”.1.当采取操作系统认证的时候,在本地用任何用户都可以以sysdba登陆:(默认方式)2.当采取口令文件认证的时候, ...