20分求助
查看原帖
20分求助
241817
Chancylaser楼主2022/8/4 02:22

AC at 1,3. other WA.

太晚先去休息了,离线等

#include<bits/stdc++.h>
#define gou 1145114
#define INF -1e18
using namespace std;
inline int read(){
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return f*x;
}
const int N=1e6+5;
int n,q;
long long a[N];

struct Tree{
	int l,r;
	long long sum,mx,all,lazy;
}t[4*N];

void build(int p,int x,int y){
	t[p].l=x,t[p].r=y;
	t[p].lazy=0; t[p].all=gou;
	if(x==y){
		t[p].sum=a[x];t[p].mx=a[x];
		return;
	}
	int mid=(x+y)>>1;
	build(p<<1,x,mid);build(p<<1|1,mid+1,y);
	t[p].sum=t[p<<1].sum+t[p<<1|1].sum;
	t[p].mx=max(t[p<<1].mx,t[p<<1|1].mx);
}

void pushdown(int p){
	if(t[p].all!=gou){
		t[p<<1].all=t[p].all,t[p<<1|1].all=t[p].all;
		t[p<<1].mx=t[p].all,t[p<<1|1].mx=t[p].all;
		t[p<<1].sum=(t[p<<1].r-t[p<<1].l+1)*t[p].all;
		t[p<<1|1].sum=(t[p<<1|1].r-t[p<<1|1].l+1)*t[p].all;
		t[p<<1].lazy=0,t[p<<1|1].lazy=0;
	}
	t[p<<1].lazy+=t[p].lazy,t[p<<1|1].lazy+=t[p].lazy;
	t[p<<1].sum+=(t[p<<1].r-t[p<<1].l+1)*t[p].lazy;
	t[p<<1|1].sum+=(t[p<<1|1].r-t[p<<1|1].l+1)*t[p].lazy;
	t[p].lazy=0; t[p].all=gou;
}

void xiu(int p,int x,int y,int k){
	if(t[p].l>y||t[p].r<x) return;
	if(t[p].l>=x&&t[p].r<=y){
		t[p].all=k; t[p].mx=k; t[p].lazy=0;
		t[p].sum=(t[p].r-t[p].l+1)*k;
		return;
	}
	pushdown(p);
	xiu(p<<1,x,y,k), xiu(p<<1|1,x,y,k);
	t[p].sum=t[p<<1].sum+t[p<<1|1].sum;
	t[p].mx=max(t[p<<1].mx,t[p<<1|1].mx);
}

void addsum(int p,int x,int y,int k){
	if(t[p].l>y||t[p].r<x) return;
	if(t[p].l>=x&&t[p].r<=y){
		t[p].mx+=k; t[p].lazy+=k;  
		t[p].sum+=(t[p].r-t[p].l+1)*k;
		return;
	}
	pushdown(p);
	addsum(p<<1,x,y,k), addsum(p<<1|1,x,y,k);
	t[p].sum=t[p<<1].sum+t[p<<1|1].sum;
	t[p].mx=max(t[p<<1].mx,t[p<<1|1].mx);
}

long long maxn(int p,int x,int y){
	if(t[p].l>y||t[p].r<x) return INF;
	if(t[p].l>=x&&t[p].r<=y) return t[p].mx;
	
	return max(maxn(p<<1,x,y),maxn(p<<1|1,x,y));
}
void cc(){
	/*for(int i=1;i<=7;i++) cout<<t[i].all<<"  ";
		cout<<endl<<endl;*/
}
int main(){
	n=read(),q=read();
	for(int i=1;i<=n;i++) a[i]=read();
	build(1,1,n);
	
	int op,l,r,x;
	for(int i=1;i<=q;i++){
		op=read();l=read(),r=read();
		if(op==1){
			x=read();
			xiu(1,l,r,x);cc();
		}
		else if(op==2){
			x=read();
			addsum(1,l,r,x);cc();
		}
		else printf("%lld\n",maxn(1,l,r));
	}
	return 0;
}
2022/8/4 02:22
加载中...