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 ...
随机推荐
- bzoj 2726: [SDOI2012]任务安排【cdq+斜率优化】
cdq复健.jpg 首先列个n方递推,设sf是f的前缀和,st是t的前缀和: \[ f[i]=min(f[j]+s*(sf[n]-sf[j])+st[i]*(sf[i]-sf[j])) \] 然后移项 ...
- bzoj 1660: [Usaco2006 Nov]Bad Hair Day 乱发节【单调栈】
开一个单调递减的单调栈,然后用sum数组维护每个点的答案,新加点的时候一边退栈一边把退掉的点的sum加进来 #include<iostream> #include<cstdio> ...
- bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘【凸包】
凸包模板 #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> ...
- hdu4738(边双连通分量,桥)
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu5122 K.Bro Sorting
思路: 模拟. 实现: #include <iostream> #include <cstdio> using namespace std; ], n, t; int main ...
- Django基础之admin功能
Django默认开起了后台 1.访问admin后台 2.用户和密码进行登录 ============================================================== ...
- 安卓app测试之内存监控
一.通过Dumpsys 来取值 1.adb shell dumpsys meminfo 获取的所有进程的内存信息,以及总内存,剩余内存,使用的内存等信息. 2.想获得某一进程内存的详细信息,在后面加上 ...
- 12Microsoft SQL Server 索引
Microsoft SQL Server 索引 8.1创建索引 CREATE INDEX idx_name ON table_name(列名) --创建非聚集索引 use student go cre ...
- HDU多校Round 3
Solved:4 rank:268 C. Dynamic Graph Matching 状压DP一下 #include <stdio.h> #include <algorithm& ...
- 【转载】dubbo约束的引入(解决eclipse中报错问题)
在采用分布式系统架构时,我们会经常使用到阿里巴巴的dubbo的分布式框架. 在相关xml配置了dubbo的约束依赖后,即使能上网eclipse.myeclipse等IDE也是无法识别dubbo的相关约 ...