/*
线段树延迟更新+状态压缩
*/
#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 线段树延迟更新+状态压缩的更多相关文章

  1. HDU 5023 A Corrupt Mayor's Performance Art 线段树区间更新+状态压缩

    Link:  http://acm.hdu.edu.cn/showproblem.php?pid=5023 #include <cstdio> #include <cstring&g ...

  2. zoj 1610 Count the Colors(线段树延迟更新)

    所谓的懒操作模板题. 学好acm,英语很重要.做题的时候看不明白题目的意思,我还拉着队友一块儿帮忙分析题意.最后确定了是线段树延迟更新果题.我就欣欣然上手敲了出来. 然后是漫长的段错误.... 第一次 ...

  3. hdu 4267 线段树间隔更新

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  4. hdu 5023 线段树+状压

    http://acm.hdu.edu.cn/showproblem.php?pid=5023 在片段上着色,有两种操作,如下: 第一种:P a b c 把 a 片段至 b 片段的颜色都变为 c . 第 ...

  5. HDU 1698 线段树 区间更新求和

    一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...

  6. hdu 1698 线段树 区间更新 区间求和

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. hdu 1166线段树 单点更新 区间求和

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  8. HDU 5023线段树区间染色,统计区间内颜色个数

    这个也是一个线段树的模板 #include<iostream> #include<string.h> #include<algorithm> #include< ...

  9. HDU 2795 线段树单点更新

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

随机推荐

  1. [Swift]Array(数组)扩展

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  2. [转]深入ASP.NET MVC之九:Ajax支持

    本文转自:http://www.cnblogs.com/yinzixin/archive/2012/12/22/2824384.html 目前前端页面和服务端进行Ajax交互大多采用的都是jQuery ...

  3. Spring Boot (27) actuator服务监控与管理

    actuaotr是spring boot项目中非常强大的一个功能,有助于对应用程序进行监控和管理,通过restful api请求来监管.审计.收集应用的运行情况,针对微服务而言它是必不可少的一个环节. ...

  4. Python学习日记之中文支持

    解决中文输出错误 在开头添加 # -*- coding: utf-8 -*- 即可

  5. Python操作远程数据库

    我的项目要往数据库中插入create_time和update_time,那就势必要引用现在的系统时间,经过大量的查找,终于发现往python是没有对应时间datetime的相关通配符的,那么我们要怎么 ...

  6. C# 客户端读取共享目录文件

    控制台应用程序 using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...

  7. key-value键值型数据库:Redis

    key-value键值型数据库:Redis redis Redis是in-memory型(内存型)的键值数据库,数据在磁盘上是持久的,键类型是字符串,值类型是字符串.字符串集合(Set).sorted ...

  8. mysql复制过滤参数说明

    参考文档: http://www.ywnds.com/?p=6945 https://stackoverflow.com/questions/23191160/whats-the-difference ...

  9. Angular——自定义服务

    基本介绍 之前我们介绍了angular内置的几种服务,这里我们介绍如何自己定义自己的服务,主要是通过三个方法:factory.service.value 基本使用 factory:可以返回对象,也可以 ...

  10. linux环境下为php7装phpredis扩展

    phpredis在php7.php5下都有不同的版本,装岔了可能会编译报错,所以在安装之前请先看下自己的php是啥版本. 我的redis装的是redis3.2.3版本. 用phpinfo()查看安装的 ...