This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |