hdu 5023 A Corrupt Mayor's Performance Art(线段树)
来源:互联网 发布:淘宝店代销如何找货源 编辑:程序博客网 时间:2024/05/16 01:25
题目链接:hdu 5023 A Corrupt Mayor's Performance Art
题目大意:给定一段区间,初始颜色为2,接诊有N次操作,P:将区间l,r涂成c,Q:查询l,r之间有哪些颜色按字典序输出。
解题思路:因为颜色的种数只有30,对于每个节点之间用一个二进制数记录即可,水水的线段树。
#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;const int maxn = 1000005;#define lson(x) ((x)<<1)#define rson(x) (((x)<<1)+1)struct Node { int l, r, s, v; void set (int l, int r, int s, int v) { this->l = l; this->r = r; this->s = s; this->v = v; } void set (int x) { this->v = x; this->s = x; }}nd[maxn * 4];int N, M;vector<int> ans;void pushup (int u) { nd[u].s = nd[lson(u)].s | nd[rson(u)].s;}void pushdown(int u) { if (nd[u].v) { nd[lson(u)].set(nd[u].v); nd[rson(u)].set(nd[u].v); nd[u].v = 0; }}void build (int u, int l, int r) { nd[u].set(l, r, 0, 0); if (l == r) { nd[u].s = 2; return ; } int mid = (l + r) / 2; build (lson(u), l, mid); build (rson(u), mid + 1, r); pushup(u);}void modify (int u, int l, int r, int x) { if (l <= nd[u].l && nd[u].r <= r) { nd[u].set(x); return;; } pushdown(u); int mid = (nd[u].l + nd[u].r) / 2; if (l <= mid) modify(lson(u), l, r, x); if (r > mid) modify(rson(u), l, r, x); pushup(u);}int query(int u, int l, int r) { if (l <= nd[u].l && nd[u].r <= r) return nd[u].s; pushdown(u); int mid = (nd[u].l + nd[u].r) / 2, ret = 0; if (l <= mid) ret |= query(lson(u), l, r); if (r > mid) ret |= query(rson(u), l, r); pushup(u); return ret;}int main () { while (scanf("%d%d", &N, &M) == 2 && N + M) { build (1, 1, N); int l, r, x; char order[10]; for (int i = 0; i < M; i++) { scanf("%s%d%d", order, &l, &r); if (order[0] == 'P') { scanf("%d", &x); modify(1, l, r, 1<<(x-1)); } else { ans.clear(); int s = query(1, l, r); for (int i = 0; i < 30; i++) if (s & (1<<i)) ans.push_back(i+1); printf("%d", ans[0]); for (int i = 1; i < ans.size(); i++) printf(" %d", ans[i]); printf("\n"); } } } return 0;}
0 0
- 【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 (线段树)
- 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 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(线段树区间更新+状态压缩)
- 干货分享:主流的App推广形式和费用详解
- 【Spark亚太研究院系列丛书】Spark实战高手之路-第一章 构建Spark集群(第四步)(4)
- 64位 windows JDK JRE 下使用xmind
- struts-config.xml配置文件详解
- Struts2学习之旅二 tiles布局和权限管理
- hdu 5023 A Corrupt Mayor's Performance Art(线段树)
- ArcGIS教程:创建经验半变异函数
- Java实现BASE64编解码
- android打印调用堆栈
- 工作报告0922
- 正则表达式工具
- unsigned 既为非负数
- Sort Colors [leetcode] 扫描数组一遍,O(1)空间复杂度的解法
- MapReduce - 性能调优