답안 #660338

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
660338 2022-11-21T16:57:52 Z emuyumi Meteors (POI11_met) C++17
74 / 100
1172 ms 27516 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

struct Fenwick{
    vector<ll> a;
    vector<int> t;
    int T;
    Fenwick(int N) : T(0), a(N), t(N) {}
    void ins(int i, ll v){
        for (++i; i < a.size(); i += i & -i){
            if (t[i] != T) a[i] = 0;
            if (a[i] <= 1e12) a[i] += v;
            t[i] = T;
        }
    }
    ll qry(int i){
        ll ret = 0;
        for (++i; i; i -= i & -i){
            if (t[i] == T) ret += a[i];
        }
        return ret;
    }
    void reset(){ T++; }
};

int main(){
    cin.tie(0)->sync_with_stdio(0);
    int N, M; cin >> N >> M;
    vector<int> o(M);
    vector<vector<int>> own(N);
    for (int i = 0; i < M; ++i){
        cin >> o[i]; o[i]--;
        own[o[i]].push_back(i);
    }
    vector<ll> need(N);
    for (int i = 0; i < N; ++i){
        cin >> need[i];
    }
    struct Meteor{ int l, r, a; };
    int Q; cin >> Q;
    vector<Meteor> qs(Q);
    for (int i = 0; i < Q; ++i){
        cin >> qs[i].l >> qs[i].r >> qs[i].a;
        qs[i].l--, qs[i].r--;
    }

    vector<int> ans(N, -1);
    Fenwick bit(M + 10);
    auto go = [&](auto self, int ql, int qr, vector<int> states) -> void{
        if (qr == ql+1){
            for (int i : states){
                ll cur = 0;
                for (int j : own[i]){
                    if (qs[ql].l > qs[ql].r){
                        if (j <= qs[ql].r || j >= qs[ql].l){
                            cur += qs[ql].a;
                        }
                    }
                    else{
                        if (qs[ql].l <= j && j <= qs[ql].r){
                            cur += qs[ql].a;
                        }
                    }
                }
                if (need[i] <= cur){
                    ans[i] = ql;
                    need[i] = 0;
                }
            }
            return;
        }

        int mid = (ql+qr) >> 1;
        bit.reset();
        for (int i = ql; i < mid; ++i){
            auto [l, r, a] = qs[i];
            if (l > r){
                bit.ins(0, a);
                bit.ins(r+1, -a);
                bit.ins(l, a);
                bit.ins(M, -a);
            }
            else{
                bit.ins(l, a);
                bit.ins(r+1, -a);
            }
        }
        vector<int> vl, vr;
        for (int i : states){
            ll cur = 0;
            for (int j : own[i]){
                cur += bit.qry(j);
            }
            if (cur >= need[i]){
                vl.push_back(i);
            }
            else{
                need[i] -= cur;
                vr.push_back(i);
            }
        }
        self(self, ql, mid, vl);
        self(self, mid, qr, vr);
    };
    vector<int> all_states(N);
    iota(all_states.begin(), all_states.end(), 0);
    go(go, 0, Q, all_states);

    // for (int i = 0; i < Q; ++i){
    //     cout << need[i] << " ";
    // }

    for (int i = 0; i < N; ++i){
        if (ans[i] == -1) cout << "NIE" << '\n';
        else cout << ans[i]+1 << '\n';
    }
}

Compilation message

met.cpp: In constructor 'Fenwick::Fenwick(int)':
met.cpp:9:9: warning: 'Fenwick::T' will be initialized after [-Wreorder]
    9 |     int T;
      |         ^
met.cpp:7:16: warning:   'std::vector<long long int> Fenwick::a' [-Wreorder]
    7 |     vector<ll> a;
      |                ^
met.cpp:10:5: warning:   when initialized here [-Wreorder]
   10 |     Fenwick(int N) : T(0), a(N), t(N) {}
      |     ^~~~~~~
met.cpp: In member function 'void Fenwick::ins(int, ll)':
met.cpp:12:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |         for (++i; i < a.size(); i += i & -i){
      |                   ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 372 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 3716 KB Output is correct
2 Correct 122 ms 7740 KB Output is correct
3 Correct 99 ms 4200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 3820 KB Output is correct
2 Correct 102 ms 3908 KB Output is correct
3 Correct 125 ms 6380 KB Output is correct
4 Correct 28 ms 3712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 3268 KB Output is correct
2 Correct 96 ms 7004 KB Output is correct
3 Correct 36 ms 1528 KB Output is correct
4 Correct 89 ms 4568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 3012 KB Output is correct
2 Correct 106 ms 4068 KB Output is correct
3 Correct 70 ms 3124 KB Output is correct
4 Correct 113 ms 5896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1145 ms 27516 KB Output is correct
2 Incorrect 761 ms 11060 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1172 ms 23656 KB Output is correct
2 Incorrect 790 ms 11120 KB Output isn't correct
3 Halted 0 ms 0 KB -