# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
501445 | nighty | Sjeckanje (COCI21_sjeckanje) | C++14 | 1 ms | 204 KiB |
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;
bool areSameSgn(long long a, long long b) {
return (a > 0 && b > 0) || (a < 0 && b < 0) || (a == b);
}
long long calc(const vector<long long>& a) {
long long res = 0;
int i = 0;
while (i + 1 < a.size()) {
int from = i;
if (a[from] == a[from + 1]) {
++i;
continue;
}
while (i + 1 < a.size() && areSameSgn(a[i + 1] - a[i], a[from + 1] - a[from])) {
++i;
}
res += abs(a[i] - a[from]);
++i;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<long long> a(n);
for (auto& i : a) {
cin >> i;
}
while (q--) {
int l, r, x;
cin >> l >> r >> x;
--l, --r;
for (int i = l; i <= r; ++i) {
a[i] += x;
}
cout << calc(a) << '\n';
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |