제출 #1232828

#제출 시각아이디문제언어결과실행 시간메모리
1232828Bui_Quoc_CuongFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
95 ms6576 KiB
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) A.begin(), A.end()
#define SZ(A) (int)A.size()
#define FOR(i, a, b) for(int i = a; i <= (int)b; i++)
#define FORD(i, a, b) for(int i = a; i >= (int)b; i--)
#define fi first
#define se second
#define pb push_back
const int N = 3e5 + 5;

int n, q, s, t;
int a[N];

long long bit[N];

void update(int u, int val){
    for(int i = u; i <= n; i+=i&-i)
        bit[i]+= val;
}

void uprange(int l, int r, int val){
    update(l, val);
    update(r + 1, - val);
}

long long get(int u){
    long long sum = 0;
    for(int i = u; i; i-=i&-i) sum+= bit[i];
    return sum;
}

void process(){
    cin >> n >> q >> s >> t;
    FOR(i, 0, n) cin >> a[i];
    FOR(i, 1, n) uprange(i, i, a[i]);
    long long ans = 0;
    FOR(i, 0, n - 1){
        if(a[i] < a[i + 1]) ans-= 1LL * s * (a[i + 1] - a[i]);
        else ans+= 1LL * t * (a[i] - a[i + 1]);
    }
    while(q--){
        int l, r, x; cin >> l >> r >> x;

        long long hl = get(l), hr = get(r);

        if(get(l - 1) < hl){
            ans+= 1LL * s * (hl - get(l - 1));
        } else ans-= 1LL * t * (get(l - 1) - hl);

        if(r < n){
            if(hr < get(r + 1)) ans+= 1LL * s * (get(r + 1) - hr);
            else ans-= 1LL * t * (hr - get(r + 1));
        }

        uprange(l, r, x);

        hl = get(l), hr = get(r);

        if(get(l - 1) < hl){
            ans-= 1LL * s * (hl - get(l - 1));
        } else ans+= 1LL * t * (get(l - 1) - hl);

        if(r < n){
            if(hr < get(r + 1)) ans-= 1LL * s * (get(r + 1) - hr);
            else ans+= 1LL * t * (hr - get(r + 1));
        }
        cout << ans << "\n";
    }
}

signed main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    #define taskname "kieuoanh"
    if(fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout);
    }

    process();

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:79:53: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout);
      |                                              ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...