# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
501445 | 2022-01-03T10:41:30 Z | nighty | Sjeckanje (COCI21_sjeckanje) | C++14 | 1 ms | 204 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 204 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 204 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 204 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |