题意:给定一个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 (据说是线段树)的更多相关文章

  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. ACM学习历程—HDU 5023 A Corrupt Mayor's Performance Art(广州赛区网赛)(线段树)

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

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

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

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

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

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

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

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

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

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

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

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

  9. HDU5023:A Corrupt Mayor's Performance Art(线段树区域更新+二进制)

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

随机推荐

  1. javaSwing文本框组件

    public class JTextFieldTest extends JFrame{    private static final long serialVersionUID = 1L;    p ...

  2. NoSQL数据库探讨之一 - 为什么要用非关系数据库?

    随着互联网web2.0网站的兴起,非关系型的数据库现在成了一个极其热门的新领域,非关系数据库产品的发展非常迅速.而传统的关系数据库在应付 web2.0网站,特别是超大规模和高并发的SNS类型的web2 ...

  3. Log4Net日志的配置

    <configuration>  <configSections>    <section name="log4net" type="log ...

  4. DIRECTORY_SEPARATOR 和 PATH_SEPARATOR的区别

    DIRECTORY_SEPARATOR:目录分隔符,linux上就是’/’    windows上是’\’ PATH_SEPARATOR:路径分隔符,include多个路径使用,在win下,当你要in ...

  5. 8.12 CSS知识点5

    背景原点 background-origin 设置元素背景图片的原始起始位置,必须保证背景是background-repeat为no-repeat此属性才会生效. 语法: background-ori ...

  6. Repeater展示表格

    1.可以不用table展示数据 <asp:Repeater ID="Repeater1" runat="server"> <ItemTempl ...

  7. Jquery Mobile 动态添加元素然后刷新 转

    Jquery Mobile 动态添加元素然后刷新 (2013-05-09 12:39:05) 转载▼ 标签: it 分类: Mobile jquery 表单元素每一个元素都有自己刷新的方法,每当改变它 ...

  8. POJ2762 UV

    题意:n个山洞,对于每两个山洞s,e,都满足s可以到达e或者e可以到达s,则输出Yes,否则输出No. ---------------------------------------- 第一个缩点的题 ...

  9. 用python监控Linux,CPU,内存,硬盘

    #!/usr/local/bin/python3.5 #coding:utf-8 import mailll, linecache, re, socket, os, time hostname = s ...

  10. CommandArgument传多个参数

    CommandArgument='<%#Eval("id")+","+Eval("interName") %>'