Submission #1154312

#TimeUsernameProblemLanguageResultExecution timeMemory
1154312CrabCNHFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
71 ms7440 KiB
#include <bits/stdc++.h>

#define task   "BriantheCrab"

#define int    long long
#define pii    pair <int, int>
#define fi     first
#define se     second
#define szf    sizeof
#define sz(s)  (int)((s).size())

using namespace std;

template <class T> void mini (T &t, T f) {if (t > f) t = f;}
template <class T> void maxi (T &t, T f) {if (t < f) t = f;}

const int maxN = 2e5 + 5;
const int inf = 1e18 + 7;
const int mod = 1e9 + 7;

int n, q, S, T;
int a[maxN], d[maxN];
int res = 0;

void add (int x, int t) {
    res += x * (x < 0 ? S : T) * (t ? 1 : -1);
    return;
}

void update (int i, int x) {
    add (d[i], 0);
    d[i] += x;
    add (d[i], 1);
    return;
}

void solve () {
    cin >> n >> q >> S >> T;
    cin >> a[0];
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
        d[i] = a[i - 1] - a[i];
        add (d[i], 1);
    }
    while (q --) {
        int l, r, x;
        cin >> l >> r >> x;
        update (l, -x);
        if (r < n) {
            update (r + 1, x);
        }
        cout << res << '\n';
    }
    return;
}

signed main () {
    cin.tie (nullptr) -> sync_with_stdio (false);
    if (fopen (task".inp", "r")) {
        freopen (task".inp", "r", stdin);
        freopen (task".out", "w", stdout);
    }
    int t = 1;
    //cin >> t;
    while (t --) {
        solve ();
    } 
    return 0;
}
// thfdgb

Compilation message (stderr)

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