HDU 5023 A Corrupt Mayor's Performance Art
来源:互联网 发布:加工中心圆弧编程100例 编辑:程序博客网 时间:2024/05/16 07:27
题意:
对一个栅栏有两种操作,一种是把从a到b的所有栅栏都刷成c,另一种是询问从a到b有多少种颜色。(栅栏初始的颜色是2)。
思路:
线段树的一道题。
利用位运算存储颜色,反正颜色只用30种,int正好够用。
利用延迟标记更新节点。
想下延伸的时候,需要把本身就置成要修改的颜色,因为标记的时候,这个节点下面的节点就应该都被修改。
Code:
#include<cstdio>#include<cstdlib>#include<cmath>#include<cstring>#include<iostream>#include<algorithm>#include<string>#include<queue>#include<stack>#include<bitset>#include<set>#include<map>#include<cctype>#include<vector>//#define TEST#define LL long long#define Mt(f, x) memset(f, x, sizeof(f));#define rep(i, s, e) for(int i = (s); i <= (e); ++i)#ifdef TEST #define See(a) cout << #a << " = " << a << endl; #define See2(a, b) cout << #a << " = " << a << ' ' << #b << " = " << b << endl; #define debug(a, s, e){ rep(_i, s, e) {cout << a[_i] << ' '; }cout << endl;} #define debug2(a, s, e, ss, ee) rep(i_, s, e) {debug(a[i_], ss, ee);}#else #define See(a) #define See2(a, b) #define debug(a, s, e) #define debug2(a, s, e, ss, ee)#endifconst int MAX = 2e9;const int MIN = -2e9;const int PI = acos(-1.0);const double eps = 1e-8;using namespace std;#define lson l, m, rt << 1#define rson m + 1, r, rt << 1 | 1const int N = 1000000 + 5;int col[N << 2], dif[N << 2];void pushUp(int rt){// See(rt); col[rt] = col[rt << 1] | col[rt << 1 | 1];}void build(int l, int r, int rt){ if(l == r) { col[rt] = 1 << 2; return ; } int m = (l + r) >> 1; build(lson); build(rson); pushUp(rt);}void pushDown(int rt){// See(rt); if(dif[rt]) { dif[rt << 1] = dif[rt << 1 | 1] = dif[rt]; col[rt << 1] = col[rt << 1 | 1] = dif[rt]; dif[rt] = 0; }}void update(int L, int R, int c, int l, int r, int rt){ if(l >= L && r <= R) {// See(rt); dif[rt] = 1 << c; col[rt] = dif[rt]; return ; } pushDown(rt); int m = (l + r) >> 1; if(L <= m) update(L, R, c, lson); if(R > m) update(L, R, c, rson); pushUp(rt);}int query(int L,int R, int l, int r, int rt){ if(l >= L && r <= R) { return col[rt]; } pushDown(rt); int ret = 0; int m = (l + r) >> 1; if(L <= m) ret |= query(L, R, lson); if(R > m) ret |= query(L, R, rson); return ret;}void print(int t){ bool first = true; for(int i = 1; i <= 30; ++i) { if(t & (1 << i)) { printf(first ? "%d" : " %d", i); first = false; } } printf("\n");}int main(){ int n, q; while(~scanf("%d%d", &n, &q)) { Mt(dif, 0); if(n + q == 0) { break; } build(1, n, 1); while(q--) { char op[2]; int a, b, c; scanf("%s%d%d", op, &a, &b); if(op[0] == 'P') { scanf("%d", &c); update(a, b, c, 1, n, 1); } else { int t = query(a, b, 1, n, 1); print(t); } } } return 0;}
0 0
- A Corrupt Mayor's Performance Art HDU
- 【HDU】5023 A Corrupt Mayor's Performance Art 线段树
- HDU 5023 A Corrupt Mayor's Performance Art
- hdu 5023 A Corrupt Mayor's Performance Art
- hdu 5023 A Corrupt Mayor's Performance Art(线段树)
- hdu 5023——A Corrupt Mayor's Performance Art
- HDU 5023 A Corrupt Mayor's Performance Art
- HDU 5023 A Corrupt Mayor's Performance Art (线段树)
- HDU 5023 A Corrupt Mayor's Performance Art
- hdu 5023-A Corrupt Mayor's Performance Art
- 【线段树】 HDU 5025 A Corrupt Mayor's Performance Art
- HDU_5023 A Corrupt Mayor's Performance Art
- B - A Corrupt Mayor's Performance Art
- HDUN 5023 A Corrupt Mayor's Performance Art
- HDOJ 5023 A Corrupt Mayor's Performance Art
- HDOJ-5023-A Corrupt Mayor's Performance Art 解题报告
- HDOJ 5023 A Corrupt Mayor's Performance Art
- HDU 5023 A Corrupt Mayor's Performance Art (线段树)
- Ubuntu14.04 下安装Matlab_R2013a 记录
- Django官方文档----编写自己的Django程序之第一步
- 笔记1
- adb工具环境配置和操作命令详解
- 把Android API文档的颜色改成不易疲劳的绿豆沙颜色
- HDU 5023 A Corrupt Mayor's Performance Art
- 如何编写高质量的程序
- TRIZ系列-创新原理-34-抛弃和再生部件原理
- 1409集合的并
- 浅谈领导和领导力
- [R] dataframe sort
- 软件的桥梁
- Linux常用命令(续)
- split 和join的使用 模仿关键词高亮显示 替换