# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
365000 | tushar_2658 | Foehn Phenomena (JOI17_foehn_phenomena) | C++14 | 158 ms | 7404 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
const int maxn = 200005;
using ll = long long;
ll a[maxn], diff[maxn];
ll S, T;
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m >> S >> T;
ll sum = 0;
ll ans = 0;
for(int i = 0; i <= n; ++i){
cin >> a[i];
if(i){
diff[i] = a[i] - a[i - 1];
if(diff[i] >= 0){
ans += diff[i] * (-S);
}else {
ans += (-diff[i]) * T;
}
}
}
while(m--){
int l, r;
ll x;
cin >> l >> r >> x;
if(diff[l] >= 0){
ans -= (diff[l] * (-S));
}else {
ans -= (-diff[l] * T);
}
if(r < n){
if(diff[r + 1] >= 0){
ans -= (diff[r + 1] * (-S));
}else {
ans -= (-diff[r + 1] * T);
}
}
diff[l] += x;
diff[r + 1] -= x;
if(diff[l] >= 0){
ans += (diff[l] * (-S));
}else {
ans += (-diff[l] * T);
}
if(r < n){
if(diff[r + 1] >= 0){
ans += (diff[r + 1] * (-S));
}else {
ans += (-diff[r + 1] * T);
}
}
cout << ans << '\n';
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |