50分求调
查看原帖
50分求调
530570
Firrel_qaq楼主2024/11/27 18:17
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#define int long long
using namespace std;
struct node{
	int val,l,r,add,ex;
}tr[8000005];
int n,q;
int op,l,r,x;
int a[8000005];
void pushdown(int p){
	if(tr[p].ex > -1e18){
		tr[p * 2].val = tr[p * 2 + 1].val = tr[p].ex;
		tr[p * 2].ex = tr[p * 2 + 1].ex = tr[p].ex;
		tr[p * 2].add = tr[p * 2 + 1].add = 0;
		tr[p].ex = -1e18;
	}
	tr[p * 2].val += tr[p].add;
	tr[p * 2 + 1].val += tr[p].add;
	tr[p * 2].add += tr[p].add;
	tr[p * 2 + 1].add += tr[p].add;
	return ;
}
void build(int p,int l,int r){
	tr[p].l = l,tr[p].r = r,tr[p].ex = -1e18;
	if(tr[p].l == tr[p].r){
		tr[p].val = a[l];
		return ;
	}
	int mid = (tr[p].l + tr[p].r) / 2;
	build(p * 2,tr[p].l,mid);
	build(p * 2 + 1,mid + 1,tr[p].r);
	tr[p].val = max(tr[p * 2].val,tr[p * 2 + 1].val);
	return ;
}
void exchange(int p,int l,int r,int k){
	if(tr[p].l >= l && tr[p].r <= r){
		tr[p].val = k;
		tr[p].ex = k;
		tr[p].add = 0;
		return ;
	}
	pushdown(p);
	int mid = (tr[p].l + tr[p].r) / 2;
	if(mid >= l) exchange(p * 2,l,r,k);
	if(mid < r) exchange(p * 2 + 1,l,r,k);
	tr[p].val = max(tr[p * 2].val,tr[p * 2 + 1].val);
	return ;
}
void add(int p,int l,int r,int k){
	if(tr[p].l >= l && tr[p].r <= r){
		tr[p].val += k;
		tr[p].add += k;
		return ;
	}
	pushdown(p);
	int mid = (tr[p].l + tr[p].r) / 2;
	if(mid >= l) add(p * 2,l,r,k);
	if(mid < r) add(p * 2 + 1,l,r,k);
	tr[p].val = max(tr[p * 2].val,tr[p * 2 + 1].val);
	return ;
}
int found(int p,int l,int r){
	if(tr[p].l >= l && tr[p].r <= r) return tr[p].val;
	pushdown(p);
	int ans = 0,mid = (tr[p].l + tr[p].r) / 2;
	if(mid >= l) ans = found(p * 2,l,r);
	if(mid < r) ans = max(found(p * 2 + 1,l,r),ans);
	return ans;
}
signed main(){
	scanf("%lld%lld",&n,&q);
	for(int i = 1;i <= n;i++) scanf("%lld",&a[i]);
	build(1,1,n);
	for(int i = 1;i <= q;i++){
		scanf("%lld%lld%lld",&op,&l,&r);
		if(op == 1){
			scanf("%lld",&x);
			exchange(1,l,r,x);
		}
		else if(op == 2){
			scanf("%lld",&x);
			add(1,l,r,x);
		}
		else printf("%lld\n",found(1,l,r));
	}
	return 0;
}

2024/11/27 18:17
加载中...