10pts 调好必关
查看原帖
10pts 调好必关
1328264
wjy7777楼主2025/7/31 14:42

我可能没了解题意,大佬们轻点喷。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,q,s,t,a[10000009],d[10000009],a0,x,y,z;
ll read() {
	ll x = 0, f = 1;
	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 x * f;
}

void write(ll x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
ll b=0;
void B(){
	b=0;
	for (int i=1;i<=n;i++){
		if (d[i]<0){
			b=b-s*abs(d[i]);
		}
		else if (d[i]>0){
			b=b+t*abs(d[i]);
		}
	}
}
signed main(){
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);
	n=read();
	q=read();
	s=read();
	t=read();
	a0=read();
	for (ll i=1;i<=n;i++){
		a[i]=read();
		d[i]=a[i-1]-a[i];
	}
	B();
	while (q--){
		x=read();
		y=read();
		z=read();
		if (d[x]<0){
			b=b+s*abs(d[x]);
		}
		else if (d[x]>0){
			b=b-t*abs(d[x]);
		}
		if (d[y+1]<0){
			b=b+s*abs(d[y+1]);
		}
		else if (d[y+1]>0){
			b=b-t*abs(d[y+1]);
		}
		d[x]=d[x]+z;
		d[y+1]=d[y+1]-z;
		if (d[x]<0){
			b=b-s*abs(d[x]);
		}
		else if (d[x]>0){
			b=b+t*abs(d[x]);
		}
		if (d[y+1]<0){
			b=b-s*abs(d[y+1]);
		}
		else if (d[y+1]>0){
			b=b+t*abs(d[y+1]);
		}
		write(b);
//		cout<<'\n';
	}
	return 0;
}
1AC 9WA
2025/7/31 14:42
加载中...