제출 #1306960

#제출 시각아이디문제언어결과실행 시간메모리
1306960ballbreakerFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
233 ms7340 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;
main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, q, s, t;
    cin >> n >> q >> s >> t;
    int a[n + 1];
    int d[n + 2] = {};
    for (int i = 0; i <= n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        d[i] = a[i] - a[i - 1];
        if (a[i - 1] < a[i]) {
            ans -= s * (a[i] - a[i - 1]);
        } else {
            ans += t * (a[i - 1] - a[i]);
        }
    }
    // cout << ans << endl;
    while (q--) {
        int l, r, x;
        cin >> l >> r >> x;
        if (d[l] > 0) {
            ans += s * d[l];
        } else {
            ans += t * d[l];
        }
        d[l] += x;
        if (d[l] > 0) {
            ans -= s * d[l];
        } else {
            ans -= t * d[l];
        }
        if (r + 1 <= n) {
            if (d[r + 1] > 0) {
                ans += s * d[r + 1];
            } else {
                ans += t * d[r + 1];
            }
            d[r + 1] -= x;
            if (d[r + 1] > 0) {
                ans -= s * d[r + 1];
            } else {
                ans -= t * d[r + 1];
            }
        }
        cout << ans << endl;
    }
}

컴파일 시 표준 에러 (stderr) 메시지

foehn_phenomena.cpp:4:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    4 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...