Submission #814644

#TimeUsernameProblemLanguageResultExecution timeMemory
814644shoryu386Sjeckanje (COCI21_sjeckanje)C++17
0 / 110
1 ms212 KiB
#include <iostream> using namespace std; #define int long long signed main(){ int n, q; cin >> n >> q; int arr[n]; for (int x = 0; x < n; x++) cin >> arr[x]; int a,b,c; for (int k = 0; k < q; k++){ cin >> a >> b >> c; a--; b--; for (int x = a; x <= b; x++) arr[x] += c; int sfmin = arr[0], sfmax = arr[0], ans = 0; for (int x = 0; x < n; x++){ sfmin = min(sfmin, arr[x]); sfmax = max(sfmax, arr[x]); if (x != 0 && (arr[x-1] <= arr[x]) != (arr[x] <= arr[x+1])) ans += sfmax - sfmin, sfmin = arr[x+1], sfmax = arr[x+1]; } ans += sfmax - sfmin; cout << ans << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...