답안 #1080832

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1080832 2024-08-29T14:42:20 Z tfgs Sjeckanje (COCI21_sjeckanje) C++17
0 / 110
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

#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(int, int)':
Main.cpp:25:15: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   25 |     return x<0&&y<0 || x>0&&y>0;
      |            ~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -