Submission #395058

# Submission time Handle Problem Language Result Execution time Memory
395058 2021-04-27T16:52:40 Z rocks03 Sjeckanje (COCI21_sjeckanje) C++14
0 / 110
1 ms 332 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << " "
#define nl cout << "\n"
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int N, Q;
vector<ll> a;

void update(int l, int r, ll k){
    rep(i, l, r + 1) a[i] += k;
}

ll get(){
    vector<ll> v;
    int i = 0;
    while(i < N){
        int j = i + 1; if(j == N) break;
        if(j < N && a[i] == a[j]){
            v.pb(0); i++; continue;
        }
        if(a[i] > a[j]){
            while(j < N && a[j - 1] > a[j]) j++;
            --j;
            v.pb(a[i] - a[j]);
        } else if(a[i] < a[j]){
            while(j < N && a[j - 1] < a[j]) j++;
            --j;
            v.pb(a[j] - a[i]);
        }
        i = j;
    }
    vector<ll> dp, dp2;
    dp = dp2 = {0, 0};
    rep(i, 0, SZ(v)){
        dp2[0] = max(dp[0], dp[1]);
        dp2[1] = max(dp[1], dp[0] + v[i]);
        swap(dp, dp2);
    }
    return max(dp[0], dp[1]);
}

void solve(){
    cin >> N >> Q;
    a = vector<ll>(N);
    rep(i, 0, N) cin >> a[i];
    rep(q, 0, Q){
        int l, r; ll k;
        cin >> l >> r >> k;
        --l, --r;
        update(l, r, k);
        cout << get() << "\n";   
    }
}
 
int main(){
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -