# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
877254 | hasan2006 | Foehn Phenomena (JOI17_foehn_phenomena) | C++17 | 915 ms | 29024 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>
using namespace std;
#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define se second
#define fi first
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"
const int N = 5e5 + 9 , mod = 1e9 + 7;
ll a[N] = {}, b[N] , c[N] , d[N] , tree[N] , lz[N];
void lazzy(int i , int l , int r){
tree[i] += lz[i] * (r - l + 1);
lz[2 * i] += lz[i];
lz[2 * i + 1] += lz[i];
lz[i] = 0;
}
ll ind;
void get(int i , int l , int r , int x , int y ,int k){
int m = (l + r) / 2;
if(x > r || y < l){
return;
}
lazzy(i , l, r);
if(l >= x && r <= y){
tree[i] += (r - l + 1) * k;
ind = tree[i];
lz[2 * i] += k;
lz[2 * i + 1] += k;
return;
}
get(2 * i , l , m , x , y , k);
get(2 * i + 1 , m + 1 , r , x , y , k);
tree[i] = tree[2 * i] + tree[2 * i + 1];
}
void solve()
{
ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn = 1e18 , mx = 0;
cin>>n>>m>>x>>y;
for(i = 0; i <= n; i++){
cin>>a[i];
if(i > 1)
b[i - 1] = b[i - 2] , c[i - 1] = c[i - 2];
if(i && a[i] >= a[i - 1]){
s -= abs(a[i] - a[i - 1]) * x;
b[i - 1]++;
}else {
s += abs(a[i] - a[i - 1]) * y;
c[i - 1]++;
}
}
while(m--){
cin>>l>>r>>k;
vector<ll>v;
get(1 , 1 , n , l, r , k);
if(l == 1)
v.pb(0);
else {
get(1 , 1 , n , l - 1, l - 1 , 0);
v.pb(ind + a[l - 1]);
}
get(1 , 1 , n , l, l , 0);
v.pb(ind + a[l]);
get(1 , 1 , n , r, r , 0);
v.pb(ind + a[r]);
if(r != n){
get(1 , 1 , n , r + 1, r + 1, 0);
v.pb(ind + a[r + 1]);
}
if(v[0] <= (v[1] - k)){
s += abs((v[1] - k) - v[0]) * x;
}else {
s -= abs((v[1] - k) - v[0]) * y;
}
if(v[0] <= v[1]){
s -= abs(v[1] - v[0]) * x;
}else {
s += abs(v[1] - v[0]) * y;
}
if(r < n){
if((v[2] - k) <= v[3]){
s += abs(v[3] - (v[2] - k)) * x;
}else {
s -= abs(v[3] - (v[2] - k)) * y;
}
if(v[2] <= v[3]){
s -= abs(v[3] - v[2]) * x;
}else {
s += abs(v[3] - v[2]) * y;
}
}
cout<<s<<"\n";
}
}
int main(){
int t = 1;
//cin>>t;
while(t--)
{
solve();
}
}
// Author : حسن
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... |