Submission #381741

# Submission time Handle Problem Language Result Execution time Memory
381741 2021-03-25T19:58:26 Z 4fecta Meteors (POI11_met) C++17
74 / 100
1178 ms 56052 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]) 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;
}
# Verdict Execution time Memory Grader output
1 Correct 18 ms 21612 KB Output is correct
2 Correct 18 ms 21612 KB Output is correct
3 Correct 18 ms 21644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 21612 KB Output is correct
2 Correct 18 ms 21612 KB Output is correct
3 Correct 19 ms 21740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 25324 KB Output is correct
2 Correct 176 ms 28540 KB Output is correct
3 Correct 138 ms 27628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 26908 KB Output is correct
2 Correct 152 ms 26988 KB Output is correct
3 Correct 181 ms 28960 KB Output is correct
4 Correct 51 ms 25196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 25708 KB Output is correct
2 Correct 174 ms 29060 KB Output is correct
3 Correct 153 ms 23580 KB Output is correct
4 Correct 142 ms 28272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 24680 KB Output is correct
2 Correct 165 ms 27112 KB Output is correct
3 Correct 110 ms 25196 KB Output is correct
4 Correct 174 ms 30316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1178 ms 56052 KB Output is correct
2 Incorrect 727 ms 36212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1124 ms 54372 KB Output is correct
2 Incorrect 769 ms 36336 KB Output isn't correct
3 Halted 0 ms 0 KB -