Submission #1103944

#TimeUsernameProblemLanguageResultExecution timeMemory
1103944normankr07Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
94 ms13204 KiB
#define taskname ""
#include <bits/stdc++.h>
#define int long long
using namespace std;
using ll = long long;

#ifndef LOCAL
#define cerr \
    if (0)   \
    cerr
#endif

const bool multitest = 0;
const int MAXN = 2e5 + 69;
int N, Q, S, T;
int A[MAXN], diff[MAXN];

void solve() {
    cin >> N >> Q >> S >> T;
    ll ans = 0;
    for(int i = 1; i <= N + 1; i++) {
        cin >> A[i];
        diff[i] = A[i] - A[i - 1];
        ans += (-diff[i]) * ((diff[i] > 0) ? S : T);
    }
    for(int i = 1; i <= Q; i++) {
        int l, r, v;
        cin >> l >> r >> v;
        l++, r++;
        ans -= (-diff[l]) * ((diff[l] > 0) ? S : T);
        diff[l] += v;
        ans += (-diff[l]) * ((diff[l] > 0) ? S : T);
        if(r != N  + 1) {
            ans -= (-diff[r + 1]) * ((diff[r + 1] > 0) ? S : T);
            diff[r + 1] -= v;
            ans += (-diff[r + 1]) * ((diff[r + 1] > 0) ? S : T);
        }
        cout << ans << "\n";
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname ".inp", "r")) {
        freopen(taskname ".inp", "r", stdin);
        freopen(taskname ".out", "w", stdout);
    }
    int tc = 1;
    if(multitest)
        cin >> tc;
    while(tc--) {
        solve();
        cout << '\n';
    }
}

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int32_t main()':
foehn_phenomena.cpp:46:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         freopen(taskname ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:47:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         freopen(taskname ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...