| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 51467 | combi2k2 | Foehn Phenomena (JOI17_foehn_phenomena) | C++14 | 0 ms | 0 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int   N   = 2e5 + 1;
int a[N], n, q, s, t;
int f(int x)    {
    if(x < 0)   return x * s;
    return x * t;
}
int main(){
    ios_base::sync_with_stdio(false);   cin.tie(0);
    cin >> n >> q >> s >> t;
    int ans = 0;
    for(int i = 0 ; i <= n ; ++i)   {
        cin >> a[i];
        if(i)   {
            a[i - 1] = a[i - 1] - a[i];
            ans += f(a[i - 1]);
        }
    }
    while(q--)  {
        int l, r, x;
        cin >> l >> r >> x;
        if(l > 0)   {
            ans -= f(a[l - 1]); a[l - 1] -= x;
            ans += f(a[l - 1]);
        }
        if(r < n)   {
            ans -= f(a[r]);     a[r] += x;
            ans += f(a[r]);
        }
        cout << ans << "\n";
    }
}
