답안 #501445

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
501445 2022-01-03T10:41:30 Z nighty Sjeckanje (COCI21_sjeckanje) C++14
0 / 110
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

Main.cpp: In function 'long long int calc(const std::vector<long long int>&)':
Main.cpp:12:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     while (i + 1 < a.size()) {
      |            ~~~~~~^~~~~~~~~~
Main.cpp:18:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         while (i + 1 < a.size() && areSameSgn(a[i + 1] - a[i], a[from + 1] - a[from])) {
      |                ~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -