답안 #532691

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532691 2022-03-03T16:11:34 Z Ai7081 Meteors (POI11_met) C++17
0 / 100
163 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;
}

void update_replace(int v, int tl, int tr, int l, int r, int val) {
    if (tr < l || tl > r) return;
    if (l <= tl && tr <= r) {
        t[v].val += val;
        return;
    }
    int tm = (tl+tr)/2;
    update_replace(t[v].l, tl, tm, l, r, val);
    update_replace(t[v].r, tm+1, tr, l, r, val);
    return;
}

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 {
            roots.push_back(update(roots[roots.size()-1], 1, m, 1, r, val));
            update_replace(roots[roots.size()-1], 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;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 8016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 8016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 92 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 134 ms 41856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 41220 KB Output is correct
2 Incorrect 135 ms 41552 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 127 ms 41816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 163 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 158 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -