Submission #231296

#TimeUsernameProblemLanguageResultExecution timeMemory
231296AlexLuchianovFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
140 ms13176 KiB
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>

using namespace std;

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 200000;
ll v[5 + nmax], dif[1 + nmax];
int s, t;

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


int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n, q;
  cin >> n >> q >> s >> t;
  for(int i = 0;i <= n; i++)
    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;
    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);
    cout << result << '\n';
  }
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...