Submission #51530

#TimeUsernameProblemLanguageResultExecution timeMemory
51530vivukhueFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
766 ms7612 KiB
#include <bits/stdc++.h> using namespace std; signed main() { long long n,q,s,t; cin>>n>>q>>s>>t; long long result = 0; long long a[n+1]; long long b[n+1]; a[0] = 0; for(long long i=0;i<=n;i++) cin>>a[i]; for(long long i=1;i<=n;i++) { b[i] = a[i-1] - a[i]; if(b[i]<0) result += b[i]*s; else result += b[i]*t; } for(long long i=0;i<q;i++) { long long l,r,x; cin>>l>>r>>x; if(l) { if(b[l]<0) result -= b[l]*s; else result -= b[l]*t; b[l] -= x; if(b[l]<0) result += b[l]*s; else result += b[l]*t; } if(r<n) { if(b[r+1]<0) result -= b[r+1]*s; else result -= b[r+1]*t; b[r+1] += x; if(b[r+1]<0) result += b[r+1]*s; else result += b[r+1]*t; } cout<<result<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...