简单暴力,求卡常加速150ms
查看原帖
简单暴力,求卡常加速150ms
689806
Civilight_Eterna楼主2024/11/21 19:22
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#ifdef ONLINE_JUDGE
#define getchar getchar_unlocked
#endif
inline void read(int &a){a=0;int f=1;char c=getchar();while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}while('0'<=c&&c<='9')a=(a<<3)+(a<<1)+c-'0',c=getchar();a*=f;}
int n,q,a[100005];
int main(){ios::sync_with_stdio(0);cout.tie(0);
//	freopen("P6792.in","r",stdin);
//	freopen("P6792.out","w",stdout);
	read(n),read(q);
	for(int i=1;i<=n;i++)read(a[i]);
	int op,l,r,x;
	ll tmp,ans;
	while(q--){
		read(op);
		if(op){
			read(l),read(r);
			if(l^r){tmp=0,ans=0;
				for(int i=l;i<=r;i++)tmp+=a[i],(tmp<0?tmp=0:ans=max(ans,tmp));
				cout<<ans<<'\n';
			}else cout<<max(a[l],0)<<'\n';
		}else{
			read(l),read(r),read(x);for(int i=l;i<=r;i++)a[i]=max(a[i],x);
		}
	}
	return 0;
}
2024/11/21 19:22
加载中...