| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 501445 | nighty | Sjeckanje (COCI21_sjeckanje) | C++14 | 1 ms | 204 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... | ||||
