Submission #404119

#TimeUsernameProblemLanguageResultExecution timeMemory
404119radaiosm7Foehn Phenomena (JOI17_foehn_phenomena)C++98
0 / 100
173 ms10436 KiB
#include <bits/stdc++.h>
using namespace std;
int n, q, i, l, r;
long long s, t, c, ans, curl1, curl2, curr1, curr2;
long long alt[200005];
long long fen[200005];

void add(long long val, int indx) {
  for (++indx; indx <= n; indx += (indx&(-indx))) {
    fen[indx] += val;
  }
}

void addlr(long long val, int l, int r) {
  add(val, l);
  add(-val, r+1);
}

long long point(int indx) {
  long long res = 0LL;
  for (++indx; indx > 0; indx -= (indx & (-indx))) {
    res += fen[indx];
  }
  return res;
}


int main() {
  scanf("%d%d%lld%lld", &n, &q, &s, &t);
  ans = 0LL;
  t *= -1LL;

  scanf("%lld", &alt[0]);

  for (i=1; i <= n; ++i) {
    scanf("%lld", &alt[i]);
    addlr(alt[i], i, i);
    if (alt[i] > alt[i-1]) {
      ans += (alt[i]-alt[i-1])*s;
    }

    else {
      ans += (alt[i-1]-alt[i])*t;
    }
  }


  while (q--) {
    scanf("%d%d%lld", &l, &r, &c);
    curl1 = point(l-1);
    curl2 = point(l);

    if (curl2 > curl1) {
      ans -= (curl2-curl1)*s;
    }

    else {
      ans -= (curl1-curl2)*t;
    }

    if (r+1 <= n) {
      curr2 = point(r+1);
      curr1 = point(r);

      if (curr2 > curr1) {
        ans -= (curr2-curr1)*s;
      }

      else {
        ans -= (curr1-curr2)*t;
      }
    }

    addlr(c, l, r);
    curl2 = point(l);
    if (curl2 > curl1) {
      ans += (curl2-curl1)*s;
    }

    else {
      ans += (curl1-curl2)*t;
    }

    if (r+1 <= n) {
      curr1 = point(r);

      if (curr2 > curr1) {
        ans += (curr2-curr1)*s;
      }

      else {
        ans += (curr1-curr2)*t;
      }
    }

    printf("%lld\n", ans);
  }

  return 0;
}

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |   scanf("%d%d%lld%lld", &n, &q, &s, &t);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   scanf("%lld", &alt[0]);
      |   ~~~~~^~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     scanf("%lld", &alt[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     scanf("%d%d%lld", &l, &r, &c);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...