Submission #951146

#TimeUsernameProblemLanguageResultExecution timeMemory
951146tnknguyen_Foehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
135 ms19540 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' const int sz = 2e5 + 5; vector<int> qr[sz]; long long a[sz], d[sz]; int n, q, s, t; // ------------ FUNCTIONS ----------- struct BIT{ vector<int> f; int n = 2e5 + 5; BIT(){ f.assign(n, 0); } void update(int i, int val){ while(i < n){ f[i] += val; i += (i & -i); } } int get(int i){ int ans = 0; while(i > 0){ ans += f[i]; i -= (i & -i); } return ans; } }; int cost(int x, int y){ return (y > x ? -s*(y - x) : t*(x - y)); } // ------------ SUBTASKS ------------ namespace SUB1{ bool ok(){ return (n <= 2000 && q <= 2000); } void solve(){ for(int i=1; i<=q; ++i){ int l = qr[i][0], r = qr[i][1], x = qr[i][2]; int ans = 0; for(int j=1; j<=n; ++j){ if(j >= l && j <= r){ a[j] += x; } if(a[j-1] < a[j]){ ans -= (a[j] - a[j-1])*s; } else{ ans += (a[j-1] - a[j])*t; } } cout<<ans<<endl; } //---------------------- exit(0); } } namespace SUB23{ void solve(){ BIT bit; int ans = 0; for(int i=1; i<=n; ++i){ bit.update(i, a[i]); bit.update(i+1, -a[i]); ans += cost(a[i-1], a[i]); } for(int i=1; i<=q; ++i){ int l = qr[i][0], r = qr[i][1], x = qr[i][2]; ans -= cost(bit.get(l-1), bit.get(l)); bit.update(l, x); ans += cost(bit.get(l-1), bit.get(l)); if(r + 1 <= n){ ans -= cost(bit.get(r), bit.get(r+1)); bit.update(r+1, -x); ans += cost(bit.get(r), bit.get(r+1)); } cout<<ans<<endl; } //-------------------- exit(0); } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("main.inp","r",stdin); //freopen("main.out","w",stdout); cin>>n>>q>>s>>t; for(int i=0; i<=n; ++i){ cin>>a[i]; } for(int i=1; i<=q; ++i){ int l, r, x; cin>>l>>r>>x; qr[i] = {l, r, x}; } if(SUB1::ok()){ SUB1::solve(); return 0; } SUB23::solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...