This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Coded by Chirath Nirodha
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define P push
#define I insert
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll mod=1e9+7;
inline void io(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
ll altseg[200010];
ll tempseg[200010];
int findalt(int pos,int l,int r,int x){
if(l==x && r==x)return altseg[pos];
int m=(l+r)/2;
if(x<=m)return altseg[pos]+findalt(2*pos,l,m,x);
else return altseg[pos]+findalt(2*pos+1,m+1,r,x);
}
void updalt(int pos,int l,int r,int x,int y,ll z){
if(l==x && r==y){
altseg[pos]+=z;
return;
}
int m=(l+r)/2;
if(y<=m)updalt(2*pos,l,m,x,y,z);
else if(x>m)updalt(2*pos+1,m+1,r,x,y,z);
else{
updalt(2*pos,l,m,x,m,z);
updalt(2*pos+1,m+1,r,m+1,y,z);
}
return;
}
int findtemp(int pos,int l,int r,int x){
if(l==x && r==x)return tempseg[pos];
int m=(l+r)/2;
if(x<=m)return tempseg[pos]+findtemp(2*pos,l,m,x);
else return tempseg[pos]+findtemp(2*pos+1,m+1,r,x);
}
void updtemp(int pos,int l,int r,int x,int y,ll z){
if(l==x && r==y){
tempseg[pos]+=z;
return;
}
int m=(l+r)/2;
if(y<=m)updtemp(2*pos,l,m,x,y,z);
else if(x>m)updtemp(2*pos+1,m+1,r,x,y,z);
else{
updtemp(2*pos,l,m,x,m,z);
updtemp(2*pos+1,m+1,r,m+1,y,z);
}
return;
}
void solve(){
io();
ll n,q,s,t;cin>>n>>q>>s>>t;
ll a[n+1];
memset(altseg,0,sizeof(altseg));
memset(tempseg,0,sizeof(tempseg));
for(int i=0;i<=n;i++){
cin>>a[i];
updalt(1,0,n,i,i,a[i]);
if(i==0)continue;
if(a[i]>a[i-1])updtemp(1,0,n,i,n,-s*(a[i]-a[i-1]));
else updtemp(1,0,n,i,n,t*(a[i-1]-a[i]));
}
while(q--){
int x,y;ll z;
cin>>x>>y>>z;
ll a,b=-1,px,py,nx,ny;
a=findalt(1,0,n,x-1);
if(y<n)b=findalt(1,0,n,y+1);
px=findalt(1,0,n,x);py=findalt(1,0,n,y);
updalt(1,0,n,x,y,z);
nx=findalt(1,0,n,x);ny=findalt(1,0,n,y);
ll tt;
if(px>a && nx<a)tt=s*(px-a)+t*(a-nx);
else if(px<a && nx>a)tt=-t*(a-px)-s*(nx-a);
else if(px>a && nx>a)tt=-s*(nx-px);
else if(px<a && nx<a)tt=-t*(nx-px);
updtemp(1,0,n,x,n,tt);
if(y==n){cout<<findtemp(1,0,n,n)<<endl;continue;}
if(b>py && b<ny)tt=s*(b-py)+t*(ny-b);
else if(b<py && b>ny)tt=-t*(py-b)-s*(b-ny);
else if(b>py && b>ny)tt=s*(ny-py);
else if(b<py && b<ny)tt=t*(ny-py);
updtemp(1,0,n,y+1,n,tt);
cout<<findtemp(1,0,n,n)<<endl;
}
}
int main(){
io();
solve();
//int t;cin>>t;for(int i=0;i<t;i++)solve();
return 0;
}
Compilation message (stderr)
foehn_phenomena.cpp: In function 'void solve()':
foehn_phenomena.cpp:95:10: warning: 'tt' may be used uninitialized in this function [-Wmaybe-uninitialized]
95 | updtemp(1,0,n,x,n,tt);
| ~~~~~~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |