Submission #783661

#TimeUsernameProblemLanguageResultExecution timeMemory
783661devariaotaFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
103 ms7216 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define endl "\n" #define pii pair<ll,ll> #define pb push_back #define vi vector<ll> #define pque priority_queue #define pqueg priority_queue<ll,vector<ll>,greater<ll>> #define que queue<ll> #define FOR(m,i,n) for(int i=(m); i<=(n); i++) #define FORM(m,i,n) for(int i=(m); i>=(n); i--) ll n,q,s,t,ans,l,r,x; ll a[200200],diff[200200]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> q >> s >> t; FOR(0,i,n) { cin >> a[i]; } FOR(1,i,n) { diff[i] = a[i] - a[i-1]; if(diff[i] > 0) { ans -= diff[i] * s; } else { ans += abs(diff[i]) * t; } } while(q--) { cin >> l >> r >> x; if(diff[l] > 0) { ans += diff[l] * s; } else { ans -= abs(diff[l]) * t; } diff[l] += x; if(diff[l] > 0) { ans -= diff[l] * s; } else { ans += abs(diff[l]) * t; } if(r != n) { if(diff[r+1] > 0) { ans += diff[r+1] * s; } else { ans -= abs(diff[r+1]) * t; } diff[r+1] -= x; if(diff[r+1] > 0) { ans -= diff[r+1] * s; } else { ans += abs(diff[r+1]) * t; } } cout << ans << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...