# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
209248 | jzh | Foehn Phenomena (JOI17_foehn_phenomena) | C++14 | 171 ms | 7288 KiB |
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>
#pragma O3
using namespace std;
typedef long long ll;
ll ft[2000005]={0};
ll ls(ll x) {
return (x & (-x));
}
ll query(ll p) {
ll sum = 0;
for(; p; p -= ls(p)) sum += ft[p];
return sum;
}
void update(ll x, ll y, ll v) {
for(; x < 2000005; x += ls(x)) ft[x] += v;
y++;
for(; y < 2000005; y += ls(x)) ft[y] -= v;}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,q,i,s,t,i1,x,y,w,sum=0,xi,yi,xf,yf,xii,yii;
cin>>n>>q>>s>>t;
ll arr[n+1];
for (i=0;i<=n;i++){
cin>>arr[i];
if (i>0)update(i,i,arr[i]);
}
for (i=1;i<=n;i++){
if (arr[i]>arr[i-1])sum-=s*(arr[i]-arr[i-1]);
else sum+=t*(arr[i-1]-arr[i]);
}
//cout<<sum<<'\n';
while (q--){
cin>>x>>y>>w;
xi=query(x);
yi=query(x-1);
xii=query(y+1);
yii=query(y);
//cout<<xi<<' '<<yi<<' '<<xii<<' '<<yii<<'\n';
update(x,y,w);
xf=query(x);
yf=query(x-1);
//cout<<xf<<' '<<yf<<' ';
if (xi>yi){
sum+=s*(xi-yi);
}
else {
sum-=t*(yi-xi);
}
if (xf<=yf){
sum+=t*(yf-xf);
}
else {
sum-=s*(xf-yf);
}
xi=xii;
yi=yii;
xf=query(y+1);
yf=query(y);
//cout<<xf<<' '<<yf<<'\n';
if (y==n){}
else {
if (xi>yi){
sum+=s*(xi-yi);
}
else {
sum-=t*(yi-xi);
}
if (xf<=yf){
sum+=t*(yf-xf);
}
else {
sum-=s*(xf-yf);
}
}
cout<<sum<<'\n';
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |