Submission #679595

#TimeUsernameProblemLanguageResultExecution timeMemory
679595tvladm2009Foehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
111 ms13140 KiB
#include <bits/stdc++.h>
#define int ll

using ll = long long;

int const nmax = 200000;

int v[5 + nmax], dif[5 + nmax];
int s, t;

int getvalue(int pos) {
  if(0 < dif[pos])
    return dif[pos] * t;
  else
    return dif[pos] * s;
}

signed main() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);

  int n, q;
  std::cin >> n >> q >> s >> t;
  for(int i = 0;i <= n; i++)
    std::cin >> v[i];
  for(int i = 0;i < n; i++)
    dif[i] = v[i] - v[i + 1];
  ll result = 0;
  for(int i = 0;i < n; i++)
    result += getvalue(i);

  for(int i = 1;i <= q; i++) {
    int x, y, val;
    std::cin >> x >> y >> val;
    result -= getvalue(x - 1);
    if(y < n)
      result -= getvalue(y);
    dif[x - 1] -= val;
    if(y < n)
      dif[y] += val;
    result += getvalue(x - 1);
    if(y < n)
      result += getvalue(y);
    std::cout << result << "\n";
  }
  return 0;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...