Submission #549415

# Submission time Handle Problem Language Result Execution time Memory
549415 2022-04-15T18:49:59 Z jesus_coconut Examination (JOI19_examination) C++17
43 / 100
163 ms 10712 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) begin(a), end(a)
#define pb push_back
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;

int const N = 100005;

int n, q;
vector<pii> v;
vector<array<int, 4>> qs;

void load() {
    cin >> n >> q;
    v.resize(n);
    qs.resize(q);
    for (auto &[a, b] : v) cin >> a >> b;
    for (int i = 0; i < q; ++i) {
        cin >> qs[i][0] >> qs[i][1] >> qs[i][2];
        qs[i][2] = max(qs[i][2], qs[i][0] + qs[i][1]);
        qs[i][3] = i;
    }
}

struct BIT {
    array<int, N> bit;

    void add(int p, int k) {
        for (++p; p < N; p += p & -p) {
            bit[p] += k;
        }
    }

    int sum(int r) {
        int val = 0;
        for (; r > 0; r -= r & -r) {
            val += bit[r];
        }
        return val;
    }

    int sum(int l, int r) {
        return sum(r) - sum(l);
    }
};

vector<int> xs, ys;

void compress() {
    xs.reserve(n);
    ys.reserve(n);
    for (auto [a, b] : v) {
        xs.pb(a);
        ys.pb(b);
    }
    sort(all(xs));
    sort(all(ys));
    xs.erase(unique(all(xs)), end(xs));
    ys.erase(unique(all(ys)), end(ys));
}

void solve() {
    sort(all(qs), [](auto const &a, auto const &b) {
        return a[2] > b[2];
    });
    sort(all(v), [](auto const &a, auto const &b) {
        return a.F + a.S > b.F + b.S;
    });
    compress();
    int sz = 0;
    vector<int> ans(q);
    BIT valx, valy;
    for (auto arr : qs) {
        while (sz < n && v[sz].F + v[sz].S >= arr[2]) {
            valx.add(lower_bound(all(xs), v[sz].F) - begin(xs), 1);
            valy.add(lower_bound(all(ys), v[sz].S) - begin(ys), 1);
            sz++;
        }
        ans[arr[3]] = sz - valx.sum(lower_bound(all(xs), arr[0]) - begin(xs)) - valy.sum(lower_bound(all(ys), arr[1]) - begin(ys));
    }
    for (auto a : ans) cout << a << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cerr << INT_MAX << endl;
    load();
    solve();


    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1088 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 5 ms 1364 KB Output is correct
8 Correct 6 ms 1364 KB Output is correct
9 Correct 5 ms 1332 KB Output is correct
10 Correct 4 ms 1236 KB Output is correct
11 Correct 4 ms 1236 KB Output is correct
12 Correct 2 ms 1236 KB Output is correct
13 Correct 4 ms 1296 KB Output is correct
14 Correct 4 ms 1364 KB Output is correct
15 Correct 4 ms 1364 KB Output is correct
16 Correct 3 ms 1236 KB Output is correct
17 Correct 4 ms 1232 KB Output is correct
18 Correct 3 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 144 ms 8412 KB Output is correct
2 Correct 130 ms 8420 KB Output is correct
3 Correct 126 ms 8428 KB Output is correct
4 Correct 86 ms 7628 KB Output is correct
5 Correct 84 ms 7664 KB Output is correct
6 Correct 54 ms 6896 KB Output is correct
7 Correct 126 ms 8308 KB Output is correct
8 Correct 132 ms 8296 KB Output is correct
9 Correct 135 ms 8268 KB Output is correct
10 Correct 71 ms 7540 KB Output is correct
11 Correct 76 ms 7532 KB Output is correct
12 Correct 49 ms 6604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 144 ms 8412 KB Output is correct
2 Correct 130 ms 8420 KB Output is correct
3 Correct 126 ms 8428 KB Output is correct
4 Correct 86 ms 7628 KB Output is correct
5 Correct 84 ms 7664 KB Output is correct
6 Correct 54 ms 6896 KB Output is correct
7 Correct 126 ms 8308 KB Output is correct
8 Correct 132 ms 8296 KB Output is correct
9 Correct 135 ms 8268 KB Output is correct
10 Correct 71 ms 7540 KB Output is correct
11 Correct 76 ms 7532 KB Output is correct
12 Correct 49 ms 6604 KB Output is correct
13 Correct 130 ms 8804 KB Output is correct
14 Correct 135 ms 8788 KB Output is correct
15 Correct 139 ms 8540 KB Output is correct
16 Correct 86 ms 8036 KB Output is correct
17 Correct 86 ms 8060 KB Output is correct
18 Correct 63 ms 6988 KB Output is correct
19 Correct 142 ms 8812 KB Output is correct
20 Correct 127 ms 8824 KB Output is correct
21 Correct 133 ms 8828 KB Output is correct
22 Correct 88 ms 7532 KB Output is correct
23 Correct 72 ms 7472 KB Output is correct
24 Correct 47 ms 6736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1088 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 5 ms 1364 KB Output is correct
8 Correct 6 ms 1364 KB Output is correct
9 Correct 5 ms 1332 KB Output is correct
10 Correct 4 ms 1236 KB Output is correct
11 Correct 4 ms 1236 KB Output is correct
12 Correct 2 ms 1236 KB Output is correct
13 Correct 4 ms 1296 KB Output is correct
14 Correct 4 ms 1364 KB Output is correct
15 Correct 4 ms 1364 KB Output is correct
16 Correct 3 ms 1236 KB Output is correct
17 Correct 4 ms 1232 KB Output is correct
18 Correct 3 ms 1236 KB Output is correct
19 Correct 144 ms 8412 KB Output is correct
20 Correct 130 ms 8420 KB Output is correct
21 Correct 126 ms 8428 KB Output is correct
22 Correct 86 ms 7628 KB Output is correct
23 Correct 84 ms 7664 KB Output is correct
24 Correct 54 ms 6896 KB Output is correct
25 Correct 126 ms 8308 KB Output is correct
26 Correct 132 ms 8296 KB Output is correct
27 Correct 135 ms 8268 KB Output is correct
28 Correct 71 ms 7540 KB Output is correct
29 Correct 76 ms 7532 KB Output is correct
30 Correct 49 ms 6604 KB Output is correct
31 Correct 130 ms 8804 KB Output is correct
32 Correct 135 ms 8788 KB Output is correct
33 Correct 139 ms 8540 KB Output is correct
34 Correct 86 ms 8036 KB Output is correct
35 Correct 86 ms 8060 KB Output is correct
36 Correct 63 ms 6988 KB Output is correct
37 Correct 142 ms 8812 KB Output is correct
38 Correct 127 ms 8824 KB Output is correct
39 Correct 133 ms 8828 KB Output is correct
40 Correct 88 ms 7532 KB Output is correct
41 Correct 72 ms 7472 KB Output is correct
42 Correct 47 ms 6736 KB Output is correct
43 Incorrect 163 ms 10712 KB Output isn't correct
44 Halted 0 ms 0 KB -