Submission #365000

#TimeUsernameProblemLanguageResultExecution timeMemory
365000tushar_2658Foehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
158 ms7404 KiB
#include "bits/stdc++.h"
using namespace std;

const int maxn = 200005;
using ll = long long;

ll a[maxn], diff[maxn];
ll S, T;

int main(int argc, char const *argv[])
{
  ios::sync_with_stdio(false); 
  cin.tie(0);

  int n, m;
  cin >> n >> m >> S >> T;
  ll sum = 0;
  ll ans = 0;
  for(int i = 0; i <= n; ++i){
    cin >> a[i];
    if(i){
      diff[i] = a[i] - a[i - 1];
      if(diff[i] >= 0){
        ans += diff[i] * (-S);
      }else {
        ans += (-diff[i]) * T;
      }
    }
  }
  while(m--){
    int l, r;
    ll x; 
    cin >> l >> r >> x; 
    if(diff[l] >= 0){
      ans -= (diff[l] * (-S));
    }else {
      ans -= (-diff[l] * T);
    }
    if(r < n){
      if(diff[r + 1] >= 0){
        ans -= (diff[r + 1] * (-S));
      }else {
        ans -= (-diff[r + 1] * T);
      }
    }
    diff[l] += x;
    diff[r + 1] -= x;
    if(diff[l] >= 0){
      ans += (diff[l] * (-S));
    }else {
      ans += (-diff[l] * T);
    }
    if(r < n){
      if(diff[r + 1] >= 0){
        ans += (diff[r + 1] * (-S));
      }else {
        ans += (-diff[r + 1] * T);
      }
    }
    cout << ans << '\n';
  }

  return 0;
}

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main(int, const char**)':
foehn_phenomena.cpp:17:6: warning: unused variable 'sum' [-Wunused-variable]
   17 |   ll sum = 0;
      |      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...