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>
using namespace std;
long long aint[800010] , v[200010];
void build (long long nod , long long st , long long dr){
long long mid = (st + dr)/2;
if (st == dr){
aint[nod] = v[st];
return;
}
build (2 * nod , st , mid);
build (2 * nod + 1 , mid + 1 , dr);
}
void update (long long nod , long long st , long long dr , long long l , long long r , long long val){
long long mid = (st + dr)/2;
if (l <= st && dr <= r){
aint[nod] += val;
return;
}
aint[2 * nod] += aint[nod];
aint[2 * nod + 1] += aint[nod];
aint[nod] = 0;
if (l <= mid)
update (2 * nod , st , mid , l , r , val);
if (mid + 1 <= r)
update (2 * nod + 1 , mid + 1 , dr , l , r , val);
}
long long query (long long nod , long long st , long long dr , long long p){
long long mid = (st + dr)/2;
if (st == dr){
return aint[nod];
}
aint[2 * nod] += aint[nod];
aint[2 * nod + 1] += aint[nod];
aint[nod] = 0;
if (p <= mid)
return query (2 * nod , st , mid , p);
else
return query (2 * nod + 1 , mid + 1 , dr , p);
}
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
long long n , i , q , s , t , sol , p1 , p2 , q1 , q2 , l , r , x;
fscanf (fin,"%lld%lld%lld%lld",&n,&q,&s,&t);
/// temp scade cu s / unitate cand alt creste
/// temp creste cu t / unitate cand alt scade
for (i = 0 ; i <= n ; i++){
fscanf (fin,"%lld",&v[i]);
}
build (1 , 0 , n);
sol = 0;
for (i = 0 ; i < n ; i++){
if (v[i] < v[i + 1])
sol = sol - s * (v[i + 1] - v[i]);
else sol = sol + t * (v[i] - v[i + 1]);
}
for (;q;q--){
fscanf (fin,"%lld%lld%lld",&l,&r,&x);
p1 = query (1 , 0 , n , l - 1);
p2 = query (1 , 0 , n , l);
if (p1 < p2)
sol = sol + s * (p2 - p1);
else sol = sol - t * (p1 - p2);
q1 = query (1 , 0 , n , r);
q2 = query (1 , 0 , n , r + 1);
if (r != n){
if (q1 < q2)
sol = sol + s * (q2 - q1);
else sol = sol - t * (q1 - q2);
}
update (1 , 0 , n , l , r , x);
p2 += x;
q1 += x;
if (p1 < p2)
sol = sol - s * (p2 - p1);
else sol = sol + t * (p1 - p2);
if (r != n){
if (q1 < q2)
sol = sol - s * (q2 - q1);
else sol = sol + t * (q1 - q2);
}
fprintf (fout,"%lld\n",sol);
}
return 0;
}
Compilation message (stderr)
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:67:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fscanf (fin,"%lld%lld%lld%lld",&n,&q,&s,&t);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:72:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fscanf (fin,"%lld",&v[i]);
~~~~~~~^~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:86:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fscanf (fin,"%lld%lld%lld",&l,&r,&x);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |