이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n, q, s, t, l, r, x, ans;
ll a[200010], diff[200010];
int main(){
cin >> n >> q >> s >> t;
for(int i=0; i<=n; i++){
cin >>a[i];
diff[i]=a[i]-a[i-1];
if(diff[i]>0) ans-=diff[i]*s;
else ans -=diff[i]*t;
}
// cout << ans << endl;
while(q--){
cin >> l >> r >> x;
ll lprev, rprev, lnow, rnow;
if(diff[l]>0) lprev=-(diff[l]*s); else lprev=-(diff[l]*t);
if(diff[r+1]>0) rprev=-(diff[r+1]*s); else rprev=-(diff[r+1]*t);
if(r+1>n) rprev=0;
// for(int i=0; i<=n; i++) cout << diff[i] << " "; cout << endl;
// cout << lprev <<" " << rprev << endl;
diff[l]+=x; diff[r+1]-=x;
if(diff[l]>0) lnow=-(diff[l]*s); else lnow=-(diff[l]*t);
if(diff[r+1]>0) rnow=-(diff[r+1]*s); else rnow=-(diff[r+1]*t);
if(r+1>n) rnow=0;
// for(int i=0; i<=n; i++) cout << diff[i] << " "; cout << endl;
// cout << lnow <<" " << rnow << endl;
ans+=(lnow-lprev)+(rnow-rprev);
cout << ans << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |