Submission #654265

# Submission time Handle Problem Language Result Execution time Memory
654265 2022-10-30T18:02:01 Z Valera_Grinenko Sjeckanje (COCI21_sjeckanje) C++17
0 / 110
1 ms 340 KB
// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
  int n, q;
  cin >> n >> q;
  vector<ll> a(n + 1);
  for(int i = 1; i <= n; i++) cin >> a[i];
  vector<ll> d(n + 1);
  for(int i = 2; i <= n; i++) d[i] = a[i] - a[i - 1];
  while(q--) {
    int l, r, x;
    cin >> l >> r >> x;
    for(int i = l; i <= r; i++) a[i] += x;
    if(l - 1 >= 1) d[l] = a[l] - a[l - 1];
    if(l + 1 <= n) d[l + 1] = a[l + 1] - a[l];
    if(r - 1 >= 1) d[r] = a[r] - a[r - 1];
    if(r + 1 <= n) d[r + 1] = a[r + 1] - a[r];
    ll ans = 0;
    for(int i = 2; i <= n; i++) {
      if(d[i] == 0) continue;
      int j = i;
      while(j + 1 <= n && (d[j + 1] == 0 || d[j + 1] < 0 == d[j] < 0)) j++;
      for(int k = i; k <= j; k++) ans += abs(d[k]);
      i = j + 1;
    }
    cout << ans << '\n';
  }
}
int main() {

  ios::sync_with_stdio(0); cin.tie(0);

  int t = 1;

  // cin >> t;

  while(t--) solve();

  return 0;
}
/*

*/

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:35:54: warning: suggest parentheses around comparison in operand of '==' [-Wparentheses]
   35 |       while(j + 1 <= n && (d[j + 1] == 0 || d[j + 1] < 0 == d[j] < 0)) j++;
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -