Submission #654272

# Submission time Handle Problem Language Result Execution time Memory
654272 2022-10-30T19:00:35 Z Valera_Grinenko Sjeckanje (COCI21_sjeckanje) C++17
0 / 110
1 ms 212 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;
    // l = rng() % n + 1, r = rng() % n + 1, x = rng() % (2 * n + 1) - n;
    // if(l > r) swap(l, r);
    for(int i = l; i <= r; i++) a[i] += x;
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
      ll l = a[i], r = a[i];
      int j = i;
      while(j + 1 <= n && !(l <= a[j + 1] && a[j + 1] <= r)) { j++; l = min(l, a[j]); r = max(r, a[j]); }
      ans += r - l;
      i = j;
    }
    cout << ans << '\n';
  }
}
int main() {

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

  int t = 1;

  // cin >> t;

  while(t--) solve();

  return 0;
}
/*
0 -2 -4 -3 -1 -1 -1 8 10 0
0 -2 -2 1 2 0 0 9 2 -10
*/
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -