Submission #1080858

#TimeUsernameProblemLanguageResultExecution timeMemory
1080858tfgsSjeckanje (COCI21_sjeckanje)C++17
0 / 110
1 ms344 KiB
#include <bits/stdc++.h> using namespace std; #define int int64_t #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 (stderr)

Main.cpp: In function 'bool sign_cmp(int64_t, int64_t)':
Main.cpp:26:15: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   26 |     return x<0&&y<0 || x>0&&y>0;
      |            ~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...