Submission #373109

#TimeUsernameProblemLanguageResultExecution timeMemory
373109sam571128Sjeckanje (COCI21_sjeckanje)C++14
0 / 110
1 ms364 KiB
#include <bits/stdc++.h> #define int long long #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; signed main(){ fastio int n,q; cin >> n >> q; int arr[n+1]; for(int i = 1;i <= n;i++){ cin >> arr[i]; } while(q--){ int l,r,x; cin >> l >> r >> x; for(int i = l;i <= r;i++) arr[i] += x; if(n==1){ cout << 0 << "\n"; continue; } int ans = 0; arr[0] = (arr[2] >= arr[1] ? -1e9 : 1e9); int inc = -1, mx = 0, mn = 0; for(int i = 1;i <= n;i++){ if(inc!=(arr[i]>=arr[i-1])){ ans += mx-mn; mx = arr[i], mn = arr[i]; inc = (arr[i]>=arr[i-1]); }else{ mx = max(arr[i],mx); mn = min(arr[i],mn); } } ans += mx-mn; cout << ans << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...