Submission #854845

#TimeUsernameProblemLanguageResultExecution timeMemory
854845NeroZeinSjeckanje (COCI21_sjeckanje)C++17
0 / 110
1 ms348 KiB
#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(int l, int r) { if (l > r) return 0; int mn = l, mx = l; for (int i = l; i <= r; ++i) { if (a[i] > a[mx]) mx = i; if (a[i] < a[mn]) mn = i; } if (mn > mx) swap(mn, mx); return abs(a[mn] - a[mx]) + solve(l, mn - 1) + solve(mx + 1, r); } 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(1, n) << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...