Submission #654529

#TimeUsernameProblemLanguageResultExecution timeMemory
654529hailFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
126 ms13064 KiB
#include <bits/stdc++.h> using namespace std; #define vi vector<int> #define vll vector<long long> #define pb push_back using ll= long long; #define fast_io ios::sync_with_stdio(0); cin.tie(0) #define inpint(x) int x; cin>>x #define inpll(x) long long x; cin>>x #define fl(i, n) for(int i=0; i<n; i++) #define flo(i, n) for(int i=1; i<=n; i++) #define int long long #define pi pair<int, int> #define mp make_pair #define ld long double const int MOD = 7 + (int)1e9; const int INF = (int)1e18; // void solve() { int n, q, s, t; cin>>n>>q>>s>>t; vector<int> a(n+1, 0); vector<int> d(n+1, 0); // a[i+1] - a[i] int ans = 0; for(int i = 0; i<=n; i++) { cin>>a[i]; } for(int i=0; i<n; i++) { d[i] = a[i+1] - a[i]; if(d[i]>=0) ans -= d[i]*s; else ans -= d[i]*t; } for(int i=1; i<=q; i++) { int l, r, x; cin>>l>>r>>x; if(l!=0) { if(d[l-1]<0) ans += d[l-1]*t; else ans += s*d[l-1]; d[l-1] += x; if(d[l-1]>=0) ans -= d[l-1]*s; else ans -= d[l-1]*t; } if(r!=n) { if(d[r]<0) ans += d[r]*t; else ans += d[r]*s; d[r] -= x; if(d[r]>=0) ans -= d[r]*s; else ans -= d[r]*t; } cout<<ans<<"\n"; } } signed main() { fast_io; int t=1; //cin>>t; while(t--) { solve(); } cout<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...