답안 #381742

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
381742 2021-03-25T20:01:45 Z 4fecta Meteors (POI11_met) C++14
74 / 100
1163 ms 65540 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define int ll
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0); cin.sync_with_stdio(0)

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

const int MN = 300005;

int n, m, a[MN], tgt[MN], l[MN], r[MN], q, bit[MN], fck1, fck2, fck3;
vector<int> pos[MN], chk[MN];
query qs[MN];

void upd(int x, int val) {
    for (int i = x + 1; i < MN; i += i & -i) bit[i] += val;
}

int qry(int x) {
    int ret = 0;
    for (int i = x + 1; i > 0; i -= i & -i) ret += bit[i];
    return ret;
}

int32_t main() {
    boost();

    cin >> n >> m;
    for (int i = 1; i <= m; i++) cin >> a[i], pos[a[i]].push_back(i);
    for (int i = 1; i <= n; i++) cin >> tgt[i];
    cin >> q;
    for (int i = 1; i <= q; i++) cin >> fck1 >> fck2 >> fck3, qs[i] = {fck1, fck2, fck3};
    for (int i = 1; i < MN; i++) l[i] = 1, r[i] = q + 1;
    for (;;) {
        bool brk = true;
        for (long long & i : bit) i = 0;
        for (int i = 1; i <= n; i++) {
            if (l[i] == r[i]) continue;
            int mid = (l[i] + r[i]) / 2;
            chk[mid].push_back(i);
        }
        for (int i = 1; i <= q; i++) {
            if (qs[i].l <= qs[i].r) upd(qs[i].l, qs[i].x), upd(qs[i].r + 1, -qs[i].x);
            else upd(1, qs[i].x), upd(qs[i].r + 1, -qs[i].x), upd(qs[i].l, qs[i].x);
            while (!chk[i].empty()) {
                int id = chk[i].back();
                chk[i].pop_back();
                int sum = 0;
                for (int p : pos[id]) {
                    sum += qry(p);
                    if (sum >= tgt[id]) break;
                }
                if (sum >= tgt[id]) r[id] = i;
                else l[id] = i + 1;
                brk = false;
            }
        }
        if (brk) break;
    }
    for (int i = 1; i <= n; i++) {
        assert(l[i] == r[i]);
        if (l[i] <= q) cout << r[i] << "\n";
        else cout << "NIE\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 21612 KB Output is correct
2 Correct 18 ms 21612 KB Output is correct
3 Correct 19 ms 21612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 21612 KB Output is correct
2 Correct 18 ms 21612 KB Output is correct
3 Correct 19 ms 21612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 24428 KB Output is correct
2 Correct 175 ms 27292 KB Output is correct
3 Correct 141 ms 26604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 25964 KB Output is correct
2 Correct 155 ms 25768 KB Output is correct
3 Correct 177 ms 27808 KB Output is correct
4 Correct 48 ms 24812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 24940 KB Output is correct
2 Correct 175 ms 27908 KB Output is correct
3 Correct 155 ms 22792 KB Output is correct
4 Correct 136 ms 27120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 23656 KB Output is correct
2 Correct 154 ms 25832 KB Output is correct
3 Correct 112 ms 24172 KB Output is correct
4 Correct 171 ms 29164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1154 ms 53364 KB Output is correct
2 Correct 743 ms 33396 KB Output is correct
3 Correct 833 ms 30060 KB Output is correct
4 Runtime error 1163 ms 65540 KB Execution killed with signal 9
# 결과 실행 시간 메모리 Grader output
1 Correct 1118 ms 51576 KB Output is correct
2 Correct 718 ms 33520 KB Output is correct
3 Correct 668 ms 29932 KB Output is correct
4 Runtime error 1079 ms 65540 KB Execution killed with signal 9