# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
758511 | dzdzx | Sjeckanje (COCI21_sjeckanje) | C++17 | 2 ms | 212 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define int long long
using namespace std;
main() {
int n,q;
cin>>n>>q;
int a[n+1];
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;
vector <int> v[n+1];
int ind=1;
v[ind].push_back(a[1]);
for (int i=2;i<=n;i++){
if (a[i]==a[i-1])ind++;
if (i>2){
if (a[i-2]<a[i-1] && a[i-1]>a[i])ind++;
if (a[i-2]>a[i-1] && a[i-1]<a[i])ind++;
}
v[ind].push_back(a[i]);
}
int ans=0;
for (int i=1;i<=n;i++){
if (v[i].size()>0){
ans+=abs(v[i][v[i].size()-1]-v[i][0]);
}
}
cout<<ans<<"\n";
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |