제출 #1351306

#제출 시각아이디문제언어결과실행 시간메모리
1351306dex111222333444555Foehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
65 ms8104 KiB
#include <bits/stdc++.h>
#define all(v) begin(v), end(v)
#define ii pair<int, int>
#define fi first
#define se second
#define siz(v) (int)(v).size()
#define lli pair<long long, int>
#define dbg(x) "[" #x " = " << x << "]"
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(i) (1LL << (i))

using namespace std;

const int mod = 1e9 + 7, infINT = 1e9 + 1321;

template<class X, class Y> bool minimize(X &x, const Y &y){return x > y ? x = y, 1: 0;}
template<class X, class Y> bool maximize(X &x, const Y &y){return x < y ? x = y, 1: 0;}

struct fenwickTree{
    int n;

    vector<long long > bit;

    fenwickTree(int _n = 0): n(_n){
        bit.assign(n + 1, 0);
    }

    void update(int pos, const long long &delta){
        for(; pos <= n; pos += pos & -pos) bit[pos] += delta;
    }

    void update(int l, int r, const long long &delta){
        update(l, +delta);
        update(r + 1, -delta);
    }

    long long get(int pos){
        long long sum = 0;
        for(; pos > 0; pos ^= pos & -pos) sum += bit[pos];
        return sum;
    }
};

const int MAXN = 1e6 + 6;

int numVal, numQuery, up, down, val[MAXN];
long long diff[MAXN];

void input(){
    cin >> numVal >> numQuery >> up >> down;
    ++numVal;
    for(int i = 1; i <= numVal; i++) cin >> val[i];
}

long long sum;

void update(const int &pos, const int &change){
    if (diff[pos] < 0) sum += 1LL * change * 1LL * up * 1LL * diff[pos];
    else sum += 1LL * change * 1LL * down * 1LL * diff[pos];
}

void solve(){
    for(int i = 2; i <= numVal; i++){
        diff[i] = val[i - 1] - val[i];
        update(i, +1);
    }

    fenwickTree bit(numVal);
    for(int i = 1; i <= numVal; i++){
        bit.update(i, i, +val[i]);
    }

    for(int q = 1; q <= numQuery; q++){
        int L, R, delta; cin >> L >> R >> delta;
        L++; R++;

        if (L > 1){
            update(L, -1);
        }
        if (R < numVal){
            update(R + 1, -1);
        }

        bit.update(L, R, +delta);

        if (L > 1){
            diff[L] = bit.get(L - 1) - bit.get(L);
            update(L, +1);
        }
        if (R < numVal){
            diff[R + 1] = bit.get(R) - bit.get(R + 1);
            update(R + 1, +1);
        }

        cout << sum << '\n';

    }
}

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    input();
    solve();
    cerr << (1.0 * clock()) / CLOCKS_PER_SEC << ".s\n";
}

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

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