Submission #1049224

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

#define left ___left
#define right ___right

struct QUERY {
    int l, r, x;
    QUERY(int l = 0, int r = 0, int x = 0) : l(l), r(r), x(x) {}
};

int N, S, T, Q;
int a[MAXN];

namespace subtask {
    void solution() {
        while(Q--) {
            int l, r, x;
            cin >> l >> r >> x;
            i64 ans = 0;
            for(int i = l; i <= r; i++) a[i] += x;
            for(int i = 0; i < N; i++)
                ans += (a[i] < a[i + 1] ? -1LL * S * (a[i + 1] - a[i]) : 1LL * T * (a[i] - a[i + 1]));
            cout << ans << "\n";
        }
    }
}

signed main() {
#define TASK "code"

    if (fopen(TASK ".inp", "r")) {
        freopen(TASK ".inp", "r", stdin);
        freopen(TASK ".ans", "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];

    subtask::solution();

    return (0 ^ 0);
}

Compilation message (stderr)

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