이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define ll long long
const int MAX=2e5+10, SS=1<<18;
ll n, q, S, T, d[2*SS+10];
void Insert(int a, int b, int w){
a+=SS-1, b+=SS+1;
while(a+1<b){
if(a%2==0) d[a+1]+=w;
if(b%2==1) d[b-1]+=w;
a/=2, b/=2;
}
}
ll Query(int a){
a+=SS;
ll wyn=0;
while(a){
wyn+=d[a];
a/=2;
}
return wyn;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin>>n>>q>>S>>T;
ll last=0, akt=0;
for(int i=1; i<=n+1; i++){
int curr;
cin>>curr;
Insert(i-1, i-1, curr);
if(i>1){
if(curr>last) akt-=(curr-last)*S;
else akt+=(last-curr)*T;
}
last=curr;
}
for(int i=1; i<=q; i++){
ll l, r, x;
cin>>l>>r>>x;
ll popLewy=Query(l-1), lewy=Query(l), prawy=Query(r), nastPrawy=Query(r+1);
if(lewy>popLewy) akt+=(lewy-popLewy)*S;
else akt-=(popLewy-lewy)*T;
if(r<n){
if(nastPrawy>prawy) akt+=(nastPrawy-prawy)*S;
else akt-=(prawy-nastPrawy)*T;
}
Insert(l, r, x);
popLewy=Query(l-1), lewy=Query(l), prawy=Query(r), nastPrawy=Query(r+1);
if(lewy>popLewy) akt-=(lewy-popLewy)*S;
else akt+=(popLewy-lewy)*T;
if(r<n){
if(nastPrawy>prawy) akt-=(nastPrawy-prawy)*S;
else akt+=(prawy-nastPrawy)*T;
}
cout<<akt<<"\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |