Submission #1050129

#TimeUsernameProblemLanguageResultExecution timeMemory
1050129manhlinh1501Foehn Phenomena (JOI17_foehn_phenomena)C++17
30 / 100
60 ms9824 KiB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int MAXN = 2e5 + 5;

int N, S, T, Q;
int a[MAXN];
i64 ans = 0;

i64 get(int p) {
    return a[p] > 0 ? -1LL * S * abs(a[p]) : 1LL * T * abs(a[p]);
}

void update(int p, int x) {
    if(p == 0 or p == N + 1) return;

    ans = ans - get(p);

    a[p] += x;

    ans = ans + get(p);
}

signed main() {
#define TASK "code"

    if (fopen(TASK ".inp", "r")) {
        freopen(TASK ".inp", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> N >> Q >> S >> T;

    for(int i = 0; i <= N; i++) cin >> a[i];

    for(int i = N; i >= 1; i--) a[i] = a[i] - a[i - 1];

    for(int i = 1; i <= N; i++) ans += get(i);
    while(Q--) {
        int l, r, x;
        cin >> l >> r >> x;
        update(l, x);
        update(r + 1, -x);
        cout << ans << "\n";
    }

    return (0 ^ 0);
}

Compilation message (stderr)

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