This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,N) for(i=0;i<N;i++)
#define FORe(i,N) for(i=1;i<=N;i++)
#define FORr(i,a,b) for(i=a;i<b;i++)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define vi vector<ll>
#define ii pair<ll,ll>
#define vii vector<ii>
const ll MAXN = 1e5;
const ll LOGN = 17;
const ll ROOTN = 320;
const ll INF = 1e17+21;
const ll MOD = 1e9 + 7;
using namespace std;
ll N,Q,S,T,i,L,R,x,temp = 0;
inline ll TEMPERATURE(ll a)
{
return ((a < 0)? (- T*a) : (- S*a));
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll prev = 0;
cin>>N>>Q>>S>>T;
N++;
ll A[N];
FOR(i,N)
{
cin>>x;
A[i] = x - prev;
prev = x;
temp += TEMPERATURE(A[i]);//(A[i] < 0) ? (A[i]*T) : (A[i]*S);
}
//cout<<"temp now = "<<temp<<endl;
//FOR(i,N)
// cout<<A[i]<<" ";
//cout<<endl;
while (Q--)
{
cin>>L>>R>>x;
A[L] += x;
temp += TEMPERATURE(A[L]) - TEMPERATURE(A[L] - x);
//cout<<"due to L = "<<L<<"we do temp+="<< TEMPERATURE(A[L]) <<" - "<< TEMPERATURE(A[L] - x)<<"; so temp = "<<temp<<endl;
if (R<N-1)
{
A[R+1] -= x;
temp += TEMPERATURE(A[R+1]) - TEMPERATURE(A[R+1] + x);
//cout<<"due to R = "<<L<<"we do temp+="<< TEMPERATURE(A[R+1]) <<" - "<< TEMPERATURE(A[R+1] + x)<<"; so temp = "<<temp<<endl;
}
//FOR(i,N)
//cout<<A[i]<<" ";
//cout<<endl;
cout<<temp<<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... |