이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define endl "\n"
#define int long long
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
* SIMPLIFY THE PROBLEM
* READ THE STATEMENT CAREFULLY
!!! if there is an specified/interesting smth(i.e. constraint) in the statement,
then you must be careful about that
*/
void solve(){
int n,q,s,t;
cin >> n >> q >> s >> t;
s*=-1;
t*=-1;
int ar[n+5];
int diff[n+5];
for(int i=0;i<=n;i++) cin >> ar[i];
for(int i=1;i<=n;i++) diff[i]=ar[i]-ar[i-1];
int ans=0;
for(int i=1;i<=n;i++){
if(diff[i]>0) ans+=s*diff[i];
else ans+=t*diff[i];
}
while(q--){
int l,r,x;
cin >> l >> r >> x;
if(diff[l]>0) ans-=s*diff[l];
else ans-=t*diff[l];
if(r+1<=n){
if(diff[r+1]>0) ans-=s*diff[r+1];
else ans-=t*diff[r+1];
}
diff[l]+=x;
diff[r+1]-=x;
if(diff[l]>0) ans+=s*diff[l];
else ans+=t*diff[l];
if(r+1<=n){
if(diff[r+1]>0) ans+=s*diff[r+1];
else ans+=t*diff[r+1];
}
cout << ans << endl;
}
}
int32_t main(){
cin.tie(0); ios::sync_with_stdio(0);
int t=1;//cin >> t;
while(t--) solve();
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... |