hdu 5023 A Corrupt Mayor's Performance Art(线段树区间更新)
来源:互联网 发布:biz是哪个国家的域名 编辑:程序博客网 时间:2024/06/11 21:54
#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>using namespace std;int tree[5001000],add[5001000];int color[50];int n,m;void pushup(int pos){tree[pos]=tree[pos<<1]|tree[pos<<1|1]; //更新父节点}void pushdown(int pos){if(add[pos]){add[pos<<1]=add[pos];add[pos<<1|1]=add[pos];tree[pos<<1]=add[pos];tree[pos<<1|1]=add[pos];add[pos]=0; //子节点更新后,父节点的延迟标记去掉}}void build(int l,int r,int pos){add[pos]=0; //初始时,所有节点都未标记if(l==r){tree[pos]=2; //初始时,颜色为2return;}int mid=(l+r)/2;build(l,mid,2*pos);build(mid+1,r,2*pos+1);pushup(pos);}void update(int L,int R,int pos,int l,int r,int val){if(l<=L&&r>=R){tree[pos]=val;add[pos]=val;return;}pushdown(pos); //向下更新int mid=(L+R)/2;if(l<=mid) update(L,mid,pos<<1,l,r,val);if(r>mid) update(mid+1,R,pos<<1|1,l,r,val);pushup(pos);}int Query(int L,int R,int pos,int l,int r){if(l<=L&&r>=R) return tree[pos];pushdown(pos);int mid=(L+R)/2;if(l>mid) Query(mid+1,R,pos<<1|1,l,r);else if(r<=mid) Query(L,mid,pos<<1,l,r);else return Query(L,mid,pos<<1,l,r)|Query(mid+1,R,pos<<1|1,l,r);}int main(){int i,j,k,a,b,c;char ch[50];while(scanf("%d%d",&n,&m)!=EOF){if(n==0||m==0) break;build(1,n,1);for(j=0;j<m;j++){scanf("%s",ch);if(ch[0]=='P'){scanf("%d%d%d",&a,&b,&c);update(1,n,1,a,b,1<<(c-1));}else{scanf("%d%d",&a,&b);int ans=Query(1,n,1,a,b);int cnt=0;for(i=1;i<=30;i++){if(ans&(1<<(i-1)))color[++cnt]=i;}for(i=1;i<cnt;i++)printf("%d ",color[i]);printf("%d\n",color[i]);}}}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 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(线段树区间合并)
- hdoj5023A Corrupt Mayor's Performance Art【线段树区间更新】
- 【线段树】 HDU 5025 A Corrupt Mayor's Performance Art
- A Corrupt Mayor's Performance Art+线段树区间更新查询
- hdu5023 A Corrupt Mayor's Performance Art(线段树+区间更新)
- hdu 5023 A Corrupt Mayor's Performance Art(区间更新+set)
- hdu 5023 A Corrupt Mayor's Performance Art 广州网络赛 线段树的区间覆盖+种类查询
- java在指定目录下执行dos命令或者bat文件
- 自定义消息
- 实验室第十二章工作报告
- php网页采集 修正版
- HDU~1272~小希的迷宫
- hdu 5023 A Corrupt Mayor's Performance Art(线段树区间更新)
- LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- 【Java.NIO】API —— Channel接口
- C#中重写、重载、隐藏的关系
- C++程序中打印错误信息和标准错误流stderr
- HDU 1051 Wooden Sticks(How to use 快排)
- Android实现三级联动下拉框 下拉列表spinner
- 回溯法实例-深度优先搜索
- iOS工程中的info.plist文件的完整研究