求助
  • 板块P4314 CPU 监控
  • 楼主xz001
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/9/19 12:40
  • 上次更新2023/11/2 19:08:22
查看原帖
求助
674967
xz001楼主2023/9/19 12:40
#include<bits/stdc++.h>
#define ls(x) ((x)<<1)
#define rs(x) ((x)<<1|1)
#define fa(x) ((x)>>1)
using namespace std;
int a[100005],T,E;
struct node{
	int l,r,maxn,laxn,mul,add;
};
node t[400005];
void push_up(int p){
	t[p].maxn = max(t[ls(p)].maxn,t[rs(p)].maxn);
	t[p].laxn = max(t[ls(p)].laxn,t[rs(p)].laxn);
	return;
}
void build(int l,int r,int p){
	t[p].l = l;
	t[p].r = r;
	t[p].mul = 1;
	if(l==r){
		t[p].maxn = a[l];
		t[p].laxn = a[l];
		return;
	}
	int mid = l + r >> 1;
	build(l,mid,ls(p));
	build(mid+1,r,rs(p));
	push_up(p);
	return;
}
void lazy_tag(int p,int mul,int add){
	t[p].maxn *= mul;
	t[p].mul *= mul;
	t[p].add *= mul;
	t[p].laxn = max(t[p].laxn,t[p].maxn);
	
	t[p].maxn += add;
	t[p].add += add;
	t[p].laxn = max(t[p].laxn,t[p].maxn);
	return;
}
void push_down(int p){
	lazy_tag(ls(p),t[p].mul,t[p].add);
	lazy_tag(rs(p),t[p].mul,t[p].add);
	t[p].mul = 1;
	t[p].add = 0;
	return;
}
void update(int l,int r,int p,int mul,int add){
	if(l <= t[p].l && t[p].r <= r){
		lazy_tag(p,mul,add);
		return;
	}
	push_down(p);
	int mid = t[p].l + t[p].r >> 1;
	if(l<=mid) update(l,r,ls(p),mul,add);
	if(r>mid) update(l,r,rs(p),mul,add);
	push_up(p);
	return;
}
int query1(int l,int r,int p){
	if(l <= t[p].l && t[p].r <= r){
		return t[p].maxn;
	}
	push_down(p);
	int mid = t[p].l + t[p].r >> 1,sum=-2147483648;
	if(l<=mid) sum=max(sum,query1(l,r,ls(p)));
	if(r>mid) sum=max(sum,query1(l,r,rs(p)));
	return sum;
}
int query2(int l,int r,int p){
	if(l <= t[p].l && t[p].r <= r){
		return t[p].laxn;
	}
	push_down(p);
	int mid = t[p].l + t[p].r >> 1,sum=-2147483648;
	if(l<=mid) sum=max(sum,query2(l,r,ls(p)));
	if(r>mid) sum=max(sum,query2(l,r,rs(p)));
	return sum;
}
int main(){
	scanf("%d",&T);
	for(int i=1;i<=T;i++){
		scanf("%d",a+i);
	}
	build(1,T,1);
	scanf("%d",&E);
	while(E--){
		char q[2];
		int x,y;
		scanf("%s%d%d",q,&x,&y);
		if(q[0]=='Q'){
			printf("%d\n",query1(x,y,1));
		}else if(q[0]=='A'){
			printf("%d\n",query2(x,y,1));
		}else if(q[0]=='P'){
			int z;
			scanf("%d",&z);
			update(x,y,1,1,z);
		}else{
			int z;
			scanf("%d",&z);
			update(x,y,1,0,z);
		}
	}
	return 0;
} 

代码有WA,求助。

2023/9/19 12:40
加载中...