#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#ifdef LOCAL
#include "algo/debug.h"
#endif
#define f first
#define s second
template<class T> using V = vector<T>;
using vi = V<int>;
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T> int lwb(V<T>& a, const T& b) { return lb(all(a),b)-begin(a); }
template<class T> int upb(V<T>& a, const T& b) { return ub(all(a),b)-begin(a); }
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a=b, true : false; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a=b, true : false; }
bool sign_cmp(int x, int y) {
if (!x || !y) return true;
return x<0&&y<0 || x>0&&y>0;
}
void solve() {
int n, q; cin >> n >> q;
vi a(n);
for (int& i : a) cin >> i;
auto eval = [&]() {
int score = 0;
for (int i = 0; i+1 < n; i++) score += abs(a[i+1]-a[i]);
for (int i = 1; i+1 < n; i++) {
if (sign_cmp(a[i]-a[i-1], a[i]-a[i+1])) {
score -= min(abs(a[i-1]-a[i]), abs(a[i]-a[i+1]));
}
}
return score;
};
while (q--) {
int l, r, x; cin >> l >> r >> x; l--;
for (int i = l; i < r; i++) a[i] += x;
cout << eval() << '\n';
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
solve();
return 0;
}
Compilation message
Main.cpp: In function 'bool sign_cmp(int64_t, int64_t)':
Main.cpp:26:15: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
26 | return x<0&&y<0 || x>0&&y>0;
| ~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |