제출 #950003

#제출 시각아이디문제언어결과실행 시간메모리
950003vjudge1Sjeckanje (COCI21_sjeckanje)C++17
55 / 110
2013 ms7920 KiB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, q; cin >> n >> q;
    vector <int> a(n);
    for ( auto &u: a ) cin >> u;
    auto f = [&](auto a){
        vector <int> dp(n);
        ar <int,2> mx = {-a[0], a[0]};
        for ( int i = 1; i < n; i++ ){
            chmax(dp[i], dp[i - 1]);
            chmax(mx[0], -a[i] + dp[i - 1]);
            chmax(mx[1], a[i] + dp[i - 1]);
            chmax(dp[i], max(mx[0] + a[i], mx[1] - a[i]));
        }
        return dp.back();
    };
    while ( q-- ){
        int l, r, x; cin >> l >> r >> x;
        --l, --r;
        for ( int i = l; i <= r; i++ ){
            a[i] += x;
        }
        cout << f(a) << ln;
    }

    cout << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...