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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define F first
#define S second
#define pb push_back
#define ld long double
#define int ll
#define pll pair <ll,ll>
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define TIME 1.0*clock()/CLOCKS_PER_SEC
using namespace std;
using namespace __gnu_pbds;
mt19937_64 gen(time(0));
int n,q;
vector <int> a;
void init() {
cin>>n>>q;
a.resize(n);
for (int i = 0;i < n;i++)
cin>>a[i];
}
ll ans = 0;
void output() {
cout<<ans<<'\n';
}
int dp[(int)(1e6) ^ 1][(int)(2)];
void solve() {
while (q--)
{
int l,r,x;
cin>>l>>r>>x;
--l;
--r;
for (int j = l;j <= r;j++)
a[j]+=x;
ans = 0;
for (int i = 0;i < n;i++)
{
dp[i][0] = dp[i][1] = 0;
}
for (int i = 1;i < n;i++)
{
if (a[i] == a[i - 1]) {
dp[i][0] = max(dp[i - 1][0],dp[i - 1][1]);
dp[i][1] = max(dp[i - 1][0],dp[i - 1][1]);
}
else if (a[i] > a[i - 1]) {
dp[i][0] = max(dp[i][0], max(dp[i - 1][1],dp[i - 1][0] + abs(a[i] - a[i - 1])));
dp[i][1] = max(dp[i - 1][0],dp[i - 1][1]);
}
else {
dp[i][0] = max(dp[i - 1][0],dp[i - 1][1]);
dp[i][1] = max(dp[i][1], max(dp[i - 1][0],dp[i - 1][1] + abs(a[i] - a[i - 1])));
}
}
for (int i = 0;i < n;i++)
ans = max({ans,dp[i][0],dp[i][1]});
output();
}
}
int32_t main() {
srand(time(0));
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
IOS;
int test;
test = 1;
while (test--) {
init();
solve();
}
exit(0);}
/*2 3 3 4*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |