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>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll int, ll int>
#define ff first
#define ss second
#define pb push_back
#pragma GCC optimize("Ofast")
using namespace std;
// debug template
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ["; _print(__VA_ARGS__)
#else
#define debug(...)
#endif
//
inline void yes() {
cout << "YES" << endl;
return;
}
inline void no() {
cout << "NO" << endl;
return;
}
template <class T>
inline void out(T temp) {
cout << temp << endl;
return;
}
// global
void init() {
// initialize
}
void solve(int case_no) {
// solve
int n, q;
cin >> n >> q;
int a[n + 1];
for (int i = 1; i <= n; i++) cin >> a[i];
while (q--) {
int l, r, x;
cin >> l >> r >> x;
for (int i = l; i <= r; i++) a[i] += x;
int ans = 0;
for (int i = 2; i <= n; i++) ans += abs(a[i] - a[i - 1]);
for (int i = 2; i <= n - 1; i++) {
if (a[i] > max(a[i - 1], a[i + 1])) {
ans -= min(abs(a[i] - a[i - 1]), abs(a[i] - a[i + 1]));
} else if (a[i] < min(a[i - 1], a[i + 1])) {
ans -= min(abs(a[i] - a[i - 1]), abs(a[i] - a[i + 1]));
}
}
out(ans);
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
srand(time(NULL));
init();
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) solve(i);
}
/*
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |