Submission #854846

# Submission time Handle Problem Language Result Execution time Memory
854846 2023-09-29T05:50:43 Z NeroZein Sjeckanje (COCI21_sjeckanje) C++17
0 / 110
0 ms 344 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif

const int N = 2e5 + 5;

long long a[N]; 

long long solve(const int n) {
  long long ret = 0; 
  for (int i = 1; i < n; ++i) {
    int p = i + 1; 
    if (a[i + 1] < a[i]) {
      while (p + 1 <= n && a[p + 1] < a[p]) {
        p++; 
      }
    } else {
      while (p + 1 <= n && a[p + 1] > a[p]) {
        p++; 
      }
    }
    ret += abs(a[i] - a[p]); 
    i = p; 
  }
  return ret;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  while (q--) {
    int l, r, x;
    cin >> l >> r >> x;
    for (int i = l; i <= r; ++i) a[i] += x;
    cout << solve(n) << '\n'; 
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -