Submission #702188

#TimeUsernameProblemLanguageResultExecution timeMemory
702188mychecksedadFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
108 ms13144 KiB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define all(x) x.begin(), x.end()
const int N = 1e6+100, M = 1e5+10, K = 20;


ll n, a[N], s, q, t, ans, b[N];
void solve(){
  cin >> n >> q >> t >> s;
  for(int i = 0; i <= n; ++i) cin >> a[i];
  ans = 0;
  a[0] = 0;
  for(int i = 1; i <= n; ++i){
    b[i] = a[i] - a[i - 1];
    if(b[i] >= 0)
      ans += t * b[i];
    else
      ans += s * b[i];
  }
  for(;q--;){
    int l, r; ll x;; cin >> l >> r >> x;
    if(b[l] >= 0)
      ans -= t * b[l];
    else
      ans -= s * b[l];
    if(r < n){
      if(b[r + 1] >= 0)
        ans -= t * b[r + 1];
      else
        ans -= s * b[r + 1];
    }

    b[l] += x;
    b[r + 1] -= x;

    if(b[l] >= 0)
      ans += t * b[l];
    else
      ans += s * b[l];
    if(r < n){
      if(b[r + 1] >= 0)
        ans += t * b[r + 1];
      else
        ans += s * b[r + 1];
    }
    cout << -ans << '\n';
  }
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int T = 1, aa;
  // cin >> T;aa=T;
  while(T--){
    // cout << "Case #" << aa-T << ": ";
    solve();
    cout << '\n';
  }
  return 0;
 
}

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:59:14: warning: unused variable 'aa' [-Wunused-variable]
   59 |   int T = 1, aa;
      |              ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...