답안 #914269

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
914269 2024-01-21T13:35:08 Z VMaksimoski008 Meteors (POI11_met) C++14
74 / 100
139 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct BIT {
    int n, n2;
    vector<ll> tree, val;

    void config(int _n) {
        n = _n + 10;
        n2 = _n;
        tree.resize(_n+60);
        val.resize(_n+60);
    }

    void add(int p, int v) {
        val[p] += v;
        for(p++; p<n; p+=p&-p) tree[p] += v;
    }

    ll query(int p) {
        ll ans = 0;
        for(p++; p>0; p-=p&-p) ans += tree[p];
        return ans;
    }

	ll sum(int l, int r) { return query(r) - query(l-1); }
    void set(int p, int v) { add(p, v - val[p]); }
    
    void clear() {
        for(ll &x : tree) x = 0;
        for(ll &x : val) x = 0;
    }
};

struct Query { int l, r, x; };

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin >> n >> m;

    vector<vector<int> > owner(n+5);
    for(int i=1; i<=m; i++) {
        int x;
        cin >> x;
        owner[x].push_back(i);
    }

    vector<ll> req(n+5);
    for(int i=1; i<=n; i++) cin >> req[i];

    int k;
    cin >> k;
    vector<Query> qus(k+5);
    for(int i=1; i<=k; i++)
        cin >> qus[i].l >> qus[i].r >> qus[i].x;

    vector<int> L(n+5, 1), R(n+5, k+1);
    bool changed = true;

    BIT bit;
    bit.config(m+1);
    vector<stack<int> > to_check(k+5);
    Query q;
    while(changed) {
        changed = false;

        bit.clear();

        for(int i=1; i<=n; i++)
            if(L[i] != R[i]) to_check[(L[i]+R[i])/2].push(i);

        for(int it=1; it<=k; it++) {
            q = qus[it];

            if(q.l <= q.r) {
                bit.add(q.l, q.x);
                bit.add(q.r+1, -q.x);
            } else {
                bit.add(q.l, q.x);
                bit.add(m+1, -q.x);

                bit.add(1, q.x);
                bit.add(q.r+1, -q.x);
            }

            while(!to_check[it].empty()) {
                changed = true;

                int u = to_check[it].top();
                to_check[it].pop();

                ll total = 0;
                for(int &x : owner[u]) {
                    total += bit.query(x);
                    if(total > req[u]) break;
                }

                if(total >= req[u]) R[u] = it;
                else L[u] = it + 1;
            }
        }
    }

    for(int i=1; i<=n; i++) {
        if(L[i] <= k) cout << L[i] << '\n';
        else cout << "NIE\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 36796 KB Output is correct
2 Correct 114 ms 38480 KB Output is correct
3 Correct 116 ms 37716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 37404 KB Output is correct
2 Correct 115 ms 37416 KB Output is correct
3 Correct 139 ms 38476 KB Output is correct
4 Correct 23 ms 6236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 36440 KB Output is correct
2 Correct 97 ms 38228 KB Output is correct
3 Correct 67 ms 35316 KB Output is correct
4 Correct 87 ms 37980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 36700 KB Output is correct
2 Correct 90 ms 37460 KB Output is correct
3 Correct 82 ms 36924 KB Output is correct
4 Correct 107 ms 38744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 125 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 131 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -