제출 #1013828

#제출 시각아이디문제언어결과실행 시간메모리
1013828snpmrnhlolFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
86 ms13136 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll N = 2e5; ll v[N + 1]; ll dif[N + 1]; ll n,q,s,t; ll ans = 0; void modify(ll i, ll x){ if(i > n || i <= 0)return; if(dif[i] > 0){ ans+=1ll*s*abs(dif[i]); }else{ ans-=1ll*t*abs(dif[i]); } dif[i] = x; if(dif[i] > 0){ ans-=1ll*s*abs(dif[i]); }else{ ans+=1ll*t*abs(dif[i]); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>q>>s>>t; for(ll i = 0;i <= n;i++){ cin>>v[i]; if(i){ dif[i] = v[i] - v[i - 1]; if(dif[i] > 0){ ans-=s*abs(dif[i]); }else{ ans+=t*abs(dif[i]); } } } for(ll i = 0;i < q;i++){ ll l,r,x; cin>>l>>r>>x; modify(l,dif[l] + x); modify(r + 1,dif[r + 1] - x); cout<<ans<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...