Submission #1017973

#TimeUsernameProblemLanguageResultExecution timeMemory
1017973vjudge1Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
83 ms13140 KiB
#include <bits/stdc++.h> #include <algorithm> #include <iostream> #include <string> using namespace std; #define FOR(i,n) for(int i=0;i<n;i++) #define ROF(i,m,n) for(int i=m;i<=n;i++) #define vi vector<int> #define pb push_back #define alle(a) a.begin(),a.end() #define all(n) begin(n), end(n) #define rall(n) rbegin(n),rend(n) #define int long long #define vecs vector<int> #define ll long long #define ss second #define ff first const int INF = 1e9; const int MOD = 1e9 + 7; void solve(){ int n, q, s, t; cin >> n >> q >> s >> t; vector<int> a(n + 1); for(int i=0;i<=n;i++){ cin >> a[i]; } vector<ll> d(n + 1); ll ans = 0; for(int i=1;i<=n;i++){ d[i] = a[i] - a[i - 1]; if(d[i] > 0){ ans -= d[i] * s; } else { ans -= d[i] * t; } } while(q--){ int l, r, x; cin >> l >> r >> x; if(d[l] > 0){ ans += d[l] * s; } else { ans += d[l] * t; } if(r + 1 <= n){ if(d[r + 1] > 0){ ans += d[r + 1] * s; } else { ans += d[r + 1] * t; } } d[l] = d[l] + x; if(r + 1 <= n){ d[r + 1] = d[r + 1] - x; } if(d[l] > 0){ ans -= d[l] * s; } else { ans -= d[l] * t; } if(r + 1 <= n){ if(d[r + 1] > 0){ ans -= d[r + 1] * s; } else { ans -= d[r + 1] * t; } } cout<<ans<<"\n"; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; while (t--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...