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 int long long
#define size(x) (int)x.size()
#define all(x) x.begin(), x.end()
template<class S, class T>
bool chmin(S& a, const T& b) {
return a > b ? (a = b) == b : false;
}
template<class S, class T>
bool chmax(S& a, const T& b) {
return a < b ? (a = b) == b : false;
}
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
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 res = 0;
for (int i = 1; i + 1 <= n; ++i) {
if (a[i + 1] == a[i]) continue;
bool flag = a[i] < a[i + 1];
int j = i;
while (j < n && a[j] != a[j + 1] && (a[j] < a[j + 1]) == flag) {
j++;
}
res += abs(a[j] - a[i]);
i = j;
}
cout << res << '\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... |