Submission #51485

#TimeUsernameProblemLanguageResultExecution timeMemory
51485FutymyCloneFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
241 ms7612 KiB
#include <bits/stdc++.h>

#define int long long

using namespace std;

const int N = 200005;

int a[N], d[N], T[N], n, q, s, t, c[N];

signed main(){
    scanf("%lld %lld %lld %lld", &n, &q, &s, &t);
    for (int i = 0; i <= n; i++) scanf("%lld", &a[i]);
    c[0] = T[0] = 0;
    d[0] = 0;

    for (int i = 1; i <= n; i++) d[i] = a[i] - a[i - 1];
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (d[i] >= 0) ans = ans - d[i] * s;
        else ans = ans - d[i] * t;
    }

    while (q--) {
        int l, r, x;
        scanf("%lld %lld %lld", &l, &r, &x);

        if (d[l] >= 0) ans = ans + d[l] * s;
        else ans = ans + d[l] * t;

        d[l] += x;
        if (d[l] >= 0) ans = ans - d[l] * s;
        else ans = ans - d[l] * t;

        if (r < n) {
            if (d[r + 1] >= 0) ans = ans + d[r + 1] * s;
            else ans = ans + d[r + 1] * t;

            d[r + 1] -= x;
            if (d[r + 1] >= 0) ans = ans - d[r + 1] * s;
            else ans = ans - d[r + 1] * t;
        }

        printf("%lld\n", ans);
    }

    return 0;
}

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld %lld %lld %lld", &n, &q, &s, &t);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:13:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 0; i <= n; i++) scanf("%lld", &a[i]);
                                  ~~~~~^~~~~~~~~~~~~~~
foehn_phenomena.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld %lld", &l, &r, &x);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...