hdu 5023 线段树延迟更新+状态压缩
/*
线段树延迟更新+状态压缩
*/
#include<stdio.h>
#define N 1100000
struct node {
int x,y,yanchi,sum;
}a[N*4];
int lower[31];
void build(int t,int x,int y) {
a[t].x=x;
a[t].y=y;
a[t].yanchi=0;
if(x==y){
a[t].sum=lower[1];
return ;
}
int temp=t<<1;
int mid=(x+y)/2;
build(temp,x,mid);
build(temp+1,mid+1,y);
a[t].sum=a[temp].sum|a[temp+1].sum;
}
void inset(int t,int x,int y,int c) {
//printf("%d %d %d\n",a[t].yanchi,a[t].x,a[t].y);
if(a[t].x==x&&a[t].y==y) {
a[t].yanchi=lower[c];
a[t].sum=lower[c];//sum和yanchi都需要改变
// printf("%d %d %d\n",x,y,lower[c]);
return ;
}
int temp=t*2;
int mid=(a[t].x+a[t].y)/2;
if(a[t].yanchi) {//如果区间a[t].x--a[t].y被操作过就赋给子区间
a[temp].yanchi=a[t].yanchi;
a[temp].sum=a[t].sum;
a[temp+1].yanchi=a[t].yanchi;
a[temp+1].sum=a[t].sum;
a[t].yanchi=0;
}
if(x>mid)inset(temp+1,x,y,c);
else
if(y<=mid)inset(temp,x,y,c);
else {
inset(temp,x,mid,c);
inset(temp+1,mid+1,y,c);
}
a[t].sum=a[temp].sum|a[temp+1].sum;
return ;
}
int qury(int t,int x,int y) {
// printf("%d %d %d\n",a[t].yanchi,a[t].x,a[t].y);
if(a[t].x==x&&a[t].y==y) {
// printf("%d\n",a[t].sum);
return a[t].sum;
}
int temp=t*2;
int mid=(a[t].x+a[t].y)/2;
if(a[t].yanchi) {//如果区间a[t].x--a[t].y被操作过就赋给子区间
a[temp].yanchi=a[t].yanchi;
a[temp].sum=a[t].sum;
a[temp+1].yanchi=a[t].yanchi;
a[temp+1].sum=a[t].sum;
a[t].yanchi=0;
}
if(x>mid)
return qury(temp+1,x,y);
else if(y<=mid)
return qury(temp,x,y);
else
return qury(temp,x,mid)|qury(temp+1,mid+1,y);
a[t].sum=a[temp+1].sum|a[temp].sum;//更新
}
int main() {
int n,m,i,j,k,ans;
char s[10];
lower[0]=1;
for(i=1;i<=30;i++)
lower[i]=lower[i-1]*2;
while(scanf("%d%d",&n,&m),n||m) {
build(1,1,n);
while(m--) {
scanf("%s",s);
if(s[0]=='P') {
scanf("%d%d%d",&i,&j,&k);
inset(1,i,j,k-1);
}
if(s[0]=='Q') {
scanf("%d%d",&i,&j);
ans=qury(1,i,j);
// printf("%d\n",ans);
k=0;
for(i=0;i<30;i++)
if(ans&lower[i]) {
if(k)
printf(" ");
printf("%d",i+1);
k=1;
} printf("\n");
}
} }
return 0;
}
hdu 5023 线段树延迟更新+状态压缩的更多相关文章
- HDU 5023 A Corrupt Mayor's Performance Art 线段树区间更新+状态压缩
Link: http://acm.hdu.edu.cn/showproblem.php?pid=5023 #include <cstdio> #include <cstring&g ...
- zoj 1610 Count the Colors(线段树延迟更新)
所谓的懒操作模板题. 学好acm,英语很重要.做题的时候看不明白题目的意思,我还拉着队友一块儿帮忙分析题意.最后确定了是线段树延迟更新果题.我就欣欣然上手敲了出来. 然后是漫长的段错误.... 第一次 ...
- hdu 4267 线段树间隔更新
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K ...
- hdu 5023 线段树+状压
http://acm.hdu.edu.cn/showproblem.php?pid=5023 在片段上着色,有两种操作,如下: 第一种:P a b c 把 a 片段至 b 片段的颜色都变为 c . 第 ...
- HDU 1698 线段树 区间更新求和
一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...
- hdu 1698 线段树 区间更新 区间求和
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 1166线段树 单点更新 区间求和
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 5023线段树区间染色,统计区间内颜色个数
这个也是一个线段树的模板 #include<iostream> #include<string.h> #include<algorithm> #include< ...
- HDU 2795 线段树单点更新
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
随机推荐
- CentOS 7 配置 Nginx 正向代理 http、https 最详解
手头项目中有使用到 nginx,因为使用的三方云服务器,想上外网需要购买外网IP的,可是有些需要用到外网却不常用的主机也挂个外网IP有点浪费了,便想使用nginx的反向代理来实现多台内网服务器使用一台 ...
- JavaScript--DOM访问子结点childNodes
访问子结点childNodes 访问选定元素节点下的所有子节点的列表,返回的值可以看作是一个数组,他具有length属性. 语法: elementNode.childNodes 注意: 如果选定的节点 ...
- hdu2031
http://acm.hdu.edu.cn/showproblem.php?pid=2031 #include<stdio.h> #include<math.h> #inclu ...
- Android 性能优化(22)*性能工具之「Hierarchy Viewer」 Hierarchy Viewer Walkthrough
Hierarchy Viewer Walkthrough 1.In this document Prerequisites Setting the ANDROID_HVPROTO variable W ...
- Python安装第三方包(setup.py)
在github上下载了records文件到本地. 解压文件 cmd切换到文件setup.py的目录下 先执行 python setup.py build 再执行python setup.py inst ...
- 【alert(1) to win】不完全攻略
alert(1) to win 一个练习XSS的平台,地址:https://alf.nu/alert1 Warmup 给出了一段JavaScript代码 function escape(s) { re ...
- (转) 淘淘商城系列——使用SolrJ查询索引库
http://blog.csdn.net/yerenyuan_pku/article/details/72908538 我们有必要在工程中写查询索引库的代码前先进行必要的测试.我们先到Solr服务页面 ...
- HDU_1024_dp
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- Array与NSArray关系
NSArray与Array之间的关系如同NSString与String之间的关系,NSArray是类类型,而Array是结构体类型,一个是引用类型,一个是值类型,它们是怎样实现无缝转换的呢?Swift ...
- 梦想CAD控件网页版标注样式
增加标注样式 _DMxDrawX::AddDimStyle 增加一个新的标注样式,如果当前已经有指定名的标注样式,就直接失败返回.详细说明如下: 参数 说明 BSTR pszName 新增加的标注样式 ...