Submission #513858

#TimeUsernameProblemLanguageResultExecution timeMemory
513858blueSjeckanje (COCI21_sjeckanje)C++17
0 / 110
1 ms304 KiB
#include <iostream> using namespace std; using ll = long long; ll* a; bool cmp(int i, int j) { if(a[i] != a[j]) return a[i] < a[j]; else return i < j; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, q; cin >> n >> q; a = new ll[1+n+1]; for(int i = 1; i <= n; i++) cin >> a[i]; a[0] = a[n+1] = 0; for(int j = 1; j <= q; j++) { ll l, r, x; cin >> l >> r >> x; for(int i = l; i <= r; i++) a[i] += x; ll res = 0; for(int i = 1; i < n; i++) res += abs(a[i] - a[i+1]); for(int i = 2; i < n; i++) { if(cmp(i, i-1) && cmp(i, i+1)) res -= min(a[i-1] - a[i], a[i+1] - a[i]); else if(cmp(i-1, i) && cmp(i+1, i)) res -= min(a[i] - a[i-1], a[i] - a[i+1]); } cout << res << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...