이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define repd(i,a,b) for(int i = (a);i >= (b);i--)
#define PB push_back
#define F first
#define S second
#define Task ""
using namespace std;
template <class T> T read(T &a){a = 0;char c = cin.get();bool nega = 0;while(!isdigit(c) && c != '-') c = cin.get();if(c == '-') nega = 1,c = cin.get();a = c - 48;c = cin.get();while(isdigit(c)) a = a * 10 + c - 48,c = cin.get();if(nega) a = -a;return a;}
template <class T> void writep(T a){if(a > 9) writep(a / 10);cout.put(a % 10 + 48);}
template <class T> void write(T a){if(a < 0) cout.put('-'),a = -a;writep(a);cout.put(' ');}
template <class T> void writeln(T a){write(a);cout.put('\n');}
const int N = 200012;
int n,q,s,t;
long long a[N],b[N];
long long ans = 0;
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// ifstream cin (Task".inp");
// ofstream cout (Task".out");
cin >> n >> q >> s >> t;
rep(i,0,n) cin >> a[i];
rep(i,1,n) b[i] = a[i-1] - a[i];
rep(i,1,n)
ans += 1ll*b[i] * (b[i] < 0 ? s : t);
while(q--)
{
int l,r,val;
cin >> l >> r >> val;
ans -= 1ll*b[l] * (b[l] < 0 ? s : t);
if(r+1 <= n)ans -= 1ll*b[r+1] * (b[r+1] < 0 ? s : t);
b[l] -= val;
b[r+1] += val;
ans += 1ll*b[l] * (b[l] < 0 ? s : t);
if(r+1 <= n)ans += 1ll*b[r+1] * (b[r+1] < 0 ? s : t);
cout << ans << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |