이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iterator>
#include <limits>
#include <list>
#include <numeric>
#include <random>
#include <ratio>
#include <sstream>
#include <utility>
#include <bitset>
#include <deque>
#include <queue>
#include <map>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <string>
#include <set>
using namespace std;
#define a first
#define b second
#define pb push_back
typedef long long int llo;
int main(){
llo n,q,s,t;
cin>>n>>q>>s>>t;
n+=1;
llo aa[n];
llo tot=0;
llo bb[n][2];
for(llo i=0;i<n;i++){
cin>>aa[i];
bb[i][0]=0;
bb[i][1]=0;
if(i>0){
if(aa[i]>aa[i-1]){
tot-=s*abs(aa[i]-aa[i-1]);
}
else{
tot+=t*abs(aa[i]-aa[i-1]);
}
}
}
// cout<<tot<<endl;
for(llo i=0;i<q;i++){
llo l,r,x;
cin>>l>>r>>x;
if(l>0){
if(aa[l]+bb[l-1][1]<bb[l][0]+aa[l-1]){
tot-=t*(abs(aa[l]+bb[l-1][1]-(bb[l][0]+aa[l-1])));
}
else{
tot+=s*(abs(aa[l]+bb[l-1][1]-(bb[l][0]+aa[l-1])));
}
bb[l-1][1]+=x;
if(aa[l]+bb[l-1][1]<bb[l][0]+aa[l-1]){
tot+=t*(abs(aa[l]+bb[l-1][1]-(bb[l][0]+aa[l-1])));
}
else{
tot-=s*(abs(aa[l]+bb[l-1][1]-(bb[l][0]+aa[l-1])));
}
}
if(r<n-1){
if(aa[r]+bb[r+1][0]<bb[r][1]+aa[r+1]){
tot+=s*(abs(aa[r]+bb[r+1][0]-(bb[r][1]+aa[r+1])));
}
else{
tot-=t*(abs(aa[r]+bb[r+1][0]-(bb[r][1]+aa[r+1])));
}
bb[r+1][0]+=x;
if(aa[r]+bb[r+1][0]<bb[r][1]+aa[r+1]){
tot-=s*(abs(aa[r]+bb[r+1][0]-(bb[r][1]+aa[r+1])));
}
else{
tot+=t*(abs(aa[r]+bb[r+1][0]-(bb[r][1]+aa[r+1])));
}
}
cout<<tot<<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... |