传送门

解题思路

  线段树打标记,刚开始想复杂了,维护了四个标记。后来才知道只需要维护一个最大值最小值即可,然后更新的时候分类讨论一下。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib> using namespace std;
const int MAXN = 2000005; inline int rd(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)) {f=ch=='-'?0:1;ch=getchar();}
while(isdigit(ch)) {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return f?x:-x;
} int n,a[MAXN],high[MAXN<<2],low[MAXN<<2],m; inline int min(int x,int y){
return x<y?x:y;
} inline int max(int x,int y){
return x>y?x:y;
} inline void pushdown(int x,int l,int r){
int mid=(l+r)>>1;
if(l==r) {
if(low[x]!=-1) a[l]=min(a[l],low[x]);
if(high[x]!=-1) a[l]=max(a[l],high[x]);
return ;
}
if(low[x]!=-1) {
if(low[x<<1]!=-1) low[x<<1]=min(low[x<<1],low[x]);
else low[x<<1]=low[x];
if(high[x<<1]>low[x]) high[x<<1]=low[x];
if(low[x<<1|1]!=-1) low[x<<1|1]=min(low[x<<1|1],low[x]);
else low[x<<1|1]=low[x];
if(high[x<<1|1]>low[x]) high[x<<1|1]=low[x];
low[x]=-1;
}
if(high[x]!=-1){
high[x<<1]=max(high[x<<1],high[x]);
if(high[x]>low[x<<1] && low[x<<1]!=-1) low[x<<1]=high[x];
high[x<<1|1]=max(high[x<<1|1],high[x]);
if(high[x]>low[x<<1|1] && low[x<<1|1]!=-1) low[x<<1|1]=high[x];
high[x]=-1;
}
} void update_h(int x,int l,int r,int L,int R,int k){
if(L<=l && r<=R) {
high[x]=max(high[x],k);
if(low[x]!=-1 && low[x]<k) low[x]=k;
if(l==r) {
if(low[x]!=-1) a[l]=min(a[l],low[x]);
if(high[x]!=-1) a[l]=max(a[l],high[x]);
}
return ;
}
int mid=(l+r)>>1;pushdown(x,l,r);
if(L<=mid) update_h(x<<1,l,mid,L,R,k);
if(mid<R) update_h(x<<1|1,mid+1,r,L,R,k);
} void update_l(int x,int l,int r,int L,int R,int k){
if(L<=l && r<=R) {
if(low[x]==-1) low[x]=k;
else low[x]=min(low[x],k);
if(high[x]!=-1 && high[x]>k) high[x]=k;
if(l==r){
if(low[x]!=-1) a[l]=min(a[l],low[x]);
if(high[x]!=-1) a[l]=max(a[l],high[x]);
}
return ;
}
int mid=(l+r)>>1;pushdown(x,l,r);
if(L<=mid) update_l(x<<1,l,mid,L,R,k);
if(mid<R) update_l(x<<1|1,mid+1,r,L,R,k);
} void query(int x,int l,int r){
if(l==r) {pushdown(x,l,r);printf("%d\n",a[l]);return ;}
int mid=(l+r)>>1;pushdown(x,l,r);
query(x<<1,l,mid);query(x<<1|1,mid+1,r);
} int main(){
memset(low,-1,sizeof(low));
memset(high,-1,sizeof(high));
n=rd(),m=rd();int op,l,r,k;
while(m--){
op=rd(),l=rd(),r=rd(),k=rd();l++;r++;
if(op==1) update_h(1,1,n,l,r,k);
else update_l(1,1,n,l,r,k);
}
query(1,1,n);
return 0;
}

最新文章

  1. Dynamics CRM 2015-Sign Out选项
  2. python函数 与 函数式编程
  3. 装b指南
  4. CSS 高级技巧汇总
  5. Git中当add错误的时候怎么办?
  6. FreeBSD 9.1安装KMS 这是一个伪命题###### ,9....
  7. YbRapidSolution.MVC项目首页分页没有起作用
  8. MySQL主从同步报Client requested master to start replication from position
  9. Laravel 用户验证Auth::attempt fail的问题
  10. Hibernate逆向代码问题
  11. VIJOS-P1635 城市连接
  12. css公共库——简介中超过长度显示省略号
  13. 理论篇-MySQL知识汇总
  14. day14 Python集合的补充
  15. android&amp;sqlsever
  16. what&#39;s the python之变量、基本数据类型
  17. WhereHows前后端配置文件
  18. Node.js实战(一)之概述
  19. all hands meeting
  20. POJ 1509 Glass Beads---最小表示法

热门文章

  1. laravel ajax提交报错Symfony\Component\HttpKernel\Exception\HttpException
  2. Collections 工具类常见方法
  3. delphi 窗体的位置和高宽度-TForm:Letf、Top、Width、Height、ClientWidth、ClientHeight
  4. 分布式项目中增加品牌前端页面出现Uncaught Error: [$injector:modulerr] bug后的原因以及改正方式
  5. [7.18NOIP模拟测试5]砍树 题解(数论分块)
  6. Python100天打卡-Day10
  7. js中的函数声明和函数表达式的区别
  8. ElasticSearch Roaring bitmap 和跳表联合查询
  9. robotframework悬浮菜单定位问题
  10. ASP.NET Core学习——前言