Submission #960330

# Submission time Handle Problem Language Result Execution time Memory
960330 2024-04-10T09:22:22 Z AeonARY Foehn Phenomena (JOI17_foehn_phenomena) C++17
0 / 100
110 ms 14600 KB
#include <bits/stdc++.h>
using namespace std;

#define Task "DATA"
#define ll long long
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FOD(i, a, b) for (int i = (a); i >= (b); i--)

const int N = 1e6 + 6;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int n, q;
ll s, t;
ll a[N], fen[N];

void update(int idx, int val) {
    while (idx <= n) {
        fen[idx] += val;
        idx += (idx & -idx);
    }
}

ll get(int idx) {
    ll res = 0;
    while (idx >= 1) {
        res += fen[idx];
        idx -= (idx & -idx);
    }
    return res;
}

int cost(int x, int y) {
    return (y > x ? -s * (y - x) : t * (x - y));
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if (fopen(Task".INP", "r")) {
        freopen(Task".INP", "r", stdin);
        freopen(Task".OUT", "w", stdout);
    }

    cin >> n >> q >> s >> t;
    FOR(i, 0, n) cin >> a[i];

    ll ans = 0;
    FOR(i, 1, n) {
        update(i, a[i]);
        update(i + 1, -a[i]);
        ans += cost(a[i - 1], a[i]);
    }

    while (q--) {
        int l, r, x;
        cin >> l >> r >> x;

        ans -= cost(get(l - 1), get(l));
        update(l, x);
        ans += cost(get(l - 1), get(l));

        if (r + 1 <= n) {
            ans -= cost(get(r), get(r + 1));
            update(r + 1, -x);
            ans += cost(get(r), get(r + 1));
        }

        cout << ans << "\n";
    }

    return 0;
}

Compilation message

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         freopen(Task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         freopen(Task".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Incorrect 2 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 108 ms 13408 KB Output is correct
2 Correct 110 ms 14032 KB Output is correct
3 Incorrect 103 ms 14600 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Incorrect 2 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -