Submission #1333991

#TimeUsernameProblemLanguageResultExecution timeMemory
1333991lywoemFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
74 ms7380 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define l(a, b, i) for (ll i = a; i < b; i++)
#define rl(a, b, i) for (ll i = a; i >= b; i--)
#define vpair vector<pair<ll, ll>>
#define inf LLONG_MAX
#define ninf LLONG_MIN

ll N, Q, S, T, L, R, X;

ll meow(ll num) {
    if (num > 0) return num * (-S);
    return num * (-T);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> N >> Q >> S >> T; vector<ll> vec(N + 1, 0);
    l(0, N + 1, i) cin >> vec[i]; // initial altitude
    
    vector<ll> dif(N + 1, 0);
    l(1, N + 1, i) dif[i] = vec[i] - vec[i - 1];

    ll init = 0; // initial temp của nhà N
    l(1, N + 1, i) {
        init += meow(dif[i]);
    }
    
    l(1, Q + 1, i) {
        cin >> L >> R >> X;
        
        init -= meow(dif[L]);
        dif[L] += X;
        init += meow(dif[L]);

        if (R + 1 < N + 1) {
            init -= meow(dif[R + 1]);
            dif[R + 1] -= X;
            init += meow(dif[R + 1]);
        } 

        cout << init << "\n";
    }
}

// Main idea: Nếu update [L, R] += X thì chỉ có hiệu (vec[L] - vec[L - 1]) và (vec[R + 1] - vec[R]) là thay đổi
// Cụ thể thì vec[L] - vec[L - 1] += X và vec[R + 1] - vec[R] -= X
// ie. dif[L] += X và dif[R + 1] -= X (nhớ check R + 1 tồn tại lol)  
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...