Submission #1208772

#TimeUsernameProblemLanguageResultExecution timeMemory
1208772andrejikusFoehn Phenomena (JOI17_foehn_phenomena)C++20
30 / 100
1095 ms3020 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); }
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)

const int N = 2e5 + 3;
ll a[N];

struct fenwick_tree {
    vector<int> bit;
    void init(int n) {
        bit.assign(n + 1, 0);
    }

    int sum(int i) {
        int s = 0;
        while (i > 0) {
            s += bit[i];
            i -= (i & (-i));
        }
        return s;
    }
    void add(int i, int val, int n) {
        while (i > 0 && i <= n) {
            bit[i] += val;
            i += (i & (-i));
        }
    }
    int get(int l, int r) {
        return sum(r) - (l > 0 ? sum(l-1) : 0);
    }
}; fenwick_tree fenwick;

void solve() {
    ll n, q, s, t; cin >> n >> q >> s >> t;
    fenwick.init(n);
    for (int i = 1; i <= n+1; i++) cin >> a[i];

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

    while (q--) {
        ll l, r, x; cin >> l >> r >> x;
        l++; r++;
        if (a[l] > a[l-1])
            ans += (a[l]-a[l-1])*s;
        else ans -= (a[l-1]-a[l])*t;

        if (r+1 <= n+1) {
            if (a[r+1] > a[r])
                ans += (a[r+1]-a[r])*s;
            else ans -= (a[r]-a[r+1])*t;
        }

        for (int j = l; j <= r; j++)
            a[j] += x;

        if (a[l] > a[l-1])
            ans -= (a[l]-a[l-1])*s;
        else ans += (a[l-1]-a[l])*t;

        if (r+1 <= n+1) {
            if (a[r+1] > a[r])
                ans -= (a[r+1]-a[r])*s;
            else ans += (a[r]-a[r+1])*t;
        }

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

signed main() {
    ios::sync_with_stdio(false); cin.tie(0);
	int t=1; //cin >> t;
	while (t--) {
        solve();
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...