제출 #1139395

#제출 시각아이디문제언어결과실행 시간메모리
1139395vako_pSjeckanje (COCI21_sjeckanje)C++20
0 / 110
0 ms320 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back const int mxN = 1e6 + 5; ll n,q,a[mxN],b[mxN]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> q; for(int i = 1; i <= n; i++){ cin >> a[i]; } while(q--){ ll l,r,x; cin >> l >> r >> x; for(int i = l; i <= r; i++) a[i] += x; for(int i = 1; i < n; i++) b[i] = a[i + 1] - a[i]; ll ans = abs(b[1]); for(int i = 2; i < n; i++){ if((b[i - 1] >= 0) != (b[i] >= 0)){ if(abs(b[i - 1]) < abs(b[i])) ans += abs(b[i]) - abs(b[i - 1]); } else ans += abs(b[i]); } cout << ans << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...