Submission #532686

# Submission time Handle Problem Language Result Execution time Memory
532686 2022-03-03T15:59:32 Z Ai7081 Meteors (POI11_met) C++17
24 / 100
148 ms 65540 KB
#include <bits/stdc++.h>
using namespace std;
#define long long long

const int N = 300005;

struct tree{
    long val;
    int l, r;
};

int n, m, q;
long want[N];
vector<int> own[N], roots;
vector<tree> t;

int build(int tl, int tr) {
    int now = t.size();
    t.push_back({0, -1, -1});
    if (tl == tr) return now;
    int tm = (tl+tr)/2;
    t[now].l = build(tl, tm);
    t[now].r = build(tm+1, tr);
    return now;
}

int update(int v, int tl, int tr, int l, int r, int val) {
    if (tr < l || tl > r) return -1;
    int now = t.size();
    t.push_back(t[v]);
    if (l <= tl && tr <= r) {
        t[now].val += val;
        return now;
    }
    int tm = (tl+tr)/2;
    int left = update(t[v].l, tl, tm, l, r, val);
    int right = update(t[v].r, tm+1, tr, l, r, val);
    if (left != -1) t[now].l = left;
    if (right != -1) t[now].r = right;
    return now;
}

long find_val(int v, int tl, int tr, int pos) {
    if (tl == tr) return t[v].val;
    int tm = (tl+tr)/2;
    if (pos <= tm) return t[v].val + find_val(t[v].l, tl, tm, pos);
    else return t[v].val + find_val(t[v].r, tm+1, tr, pos);
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m;
    for (int i=1; i<=m; i++) {
        int x;
        cin >> x;
        own[x].push_back(i);
    }
    for (int i=1; i<=n; i++) cin >> want[i];
    roots.push_back(build(1, m));
    cin >> q;
    for (int i=1; i<=q; i++) {
        int l, r;
        long val;
        cin >> l >> r >> val;
        if (l <= r) roots.push_back(update(roots[roots.size()-1], 1, m, l, r, val));
        else {
            int tmp = update(roots[roots.size()-1], 1, m, 1, r, val);
            roots.push_back(update(tmp, 1, m, l, m, val));
        }
    }
    for (int i=1; i<=n; i++) {
        int l = 1, r = q+1;
        while (l < r) {
            long sum = 0;
            int mid = (l+r)/2;
            for (auto it : own[i]) sum += find_val(roots[mid], 1, m, it);
            if (sum < want[i]) l = mid+1;
            else r = mid;
        }
        if (l == q+1) cout << "NIE" << endl;
        else cout << l << endl;
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8016 KB Output is correct
2 Correct 6 ms 8028 KB Output is correct
3 Correct 6 ms 8016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8140 KB Output is correct
2 Correct 6 ms 8016 KB Output is correct
3 Correct 7 ms 8016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 91 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 93 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 93 ms 41748 KB Output is correct
2 Correct 133 ms 42404 KB Output is correct
3 Correct 48 ms 41296 KB Output is correct
4 Runtime error 95 ms 65540 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 97 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 148 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 146 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -