답안 #549419

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
549419 2022-04-15T18:58:04 Z jesus_coconut Examination (JOI19_examination) C++17
100 / 100
153 ms 12404 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 = 300005;

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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2632 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 5 ms 2900 KB Output is correct
8 Correct 5 ms 2952 KB Output is correct
9 Correct 5 ms 2900 KB Output is correct
10 Correct 4 ms 2900 KB Output is correct
11 Correct 4 ms 2816 KB Output is correct
12 Correct 4 ms 2772 KB Output is correct
13 Correct 5 ms 2900 KB Output is correct
14 Correct 5 ms 2900 KB Output is correct
15 Correct 5 ms 2900 KB Output is correct
16 Correct 4 ms 2772 KB Output is correct
17 Correct 4 ms 2900 KB Output is correct
18 Correct 3 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 8636 KB Output is correct
2 Correct 126 ms 8652 KB Output is correct
3 Correct 135 ms 8688 KB Output is correct
4 Correct 85 ms 8736 KB Output is correct
5 Correct 84 ms 8648 KB Output is correct
6 Correct 57 ms 8452 KB Output is correct
7 Correct 124 ms 8652 KB Output is correct
8 Correct 122 ms 8696 KB Output is correct
9 Correct 116 ms 8780 KB Output is correct
10 Correct 72 ms 8512 KB Output is correct
11 Correct 77 ms 8504 KB Output is correct
12 Correct 52 ms 8084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 8636 KB Output is correct
2 Correct 126 ms 8652 KB Output is correct
3 Correct 135 ms 8688 KB Output is correct
4 Correct 85 ms 8736 KB Output is correct
5 Correct 84 ms 8648 KB Output is correct
6 Correct 57 ms 8452 KB Output is correct
7 Correct 124 ms 8652 KB Output is correct
8 Correct 122 ms 8696 KB Output is correct
9 Correct 116 ms 8780 KB Output is correct
10 Correct 72 ms 8512 KB Output is correct
11 Correct 77 ms 8504 KB Output is correct
12 Correct 52 ms 8084 KB Output is correct
13 Correct 138 ms 8668 KB Output is correct
14 Correct 130 ms 8568 KB Output is correct
15 Correct 129 ms 8640 KB Output is correct
16 Correct 88 ms 8596 KB Output is correct
17 Correct 86 ms 8568 KB Output is correct
18 Correct 58 ms 8452 KB Output is correct
19 Correct 130 ms 8612 KB Output is correct
20 Correct 132 ms 8588 KB Output is correct
21 Correct 131 ms 8648 KB Output is correct
22 Correct 75 ms 8556 KB Output is correct
23 Correct 72 ms 8484 KB Output is correct
24 Correct 47 ms 8076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2632 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 5 ms 2900 KB Output is correct
8 Correct 5 ms 2952 KB Output is correct
9 Correct 5 ms 2900 KB Output is correct
10 Correct 4 ms 2900 KB Output is correct
11 Correct 4 ms 2816 KB Output is correct
12 Correct 4 ms 2772 KB Output is correct
13 Correct 5 ms 2900 KB Output is correct
14 Correct 5 ms 2900 KB Output is correct
15 Correct 5 ms 2900 KB Output is correct
16 Correct 4 ms 2772 KB Output is correct
17 Correct 4 ms 2900 KB Output is correct
18 Correct 3 ms 2772 KB Output is correct
19 Correct 127 ms 8636 KB Output is correct
20 Correct 126 ms 8652 KB Output is correct
21 Correct 135 ms 8688 KB Output is correct
22 Correct 85 ms 8736 KB Output is correct
23 Correct 84 ms 8648 KB Output is correct
24 Correct 57 ms 8452 KB Output is correct
25 Correct 124 ms 8652 KB Output is correct
26 Correct 122 ms 8696 KB Output is correct
27 Correct 116 ms 8780 KB Output is correct
28 Correct 72 ms 8512 KB Output is correct
29 Correct 77 ms 8504 KB Output is correct
30 Correct 52 ms 8084 KB Output is correct
31 Correct 138 ms 8668 KB Output is correct
32 Correct 130 ms 8568 KB Output is correct
33 Correct 129 ms 8640 KB Output is correct
34 Correct 88 ms 8596 KB Output is correct
35 Correct 86 ms 8568 KB Output is correct
36 Correct 58 ms 8452 KB Output is correct
37 Correct 130 ms 8612 KB Output is correct
38 Correct 132 ms 8588 KB Output is correct
39 Correct 131 ms 8648 KB Output is correct
40 Correct 75 ms 8556 KB Output is correct
41 Correct 72 ms 8484 KB Output is correct
42 Correct 47 ms 8076 KB Output is correct
43 Correct 148 ms 8712 KB Output is correct
44 Correct 153 ms 12404 KB Output is correct
45 Correct 145 ms 12288 KB Output is correct
46 Correct 92 ms 10744 KB Output is correct
47 Correct 97 ms 10740 KB Output is correct
48 Correct 59 ms 8440 KB Output is correct
49 Correct 138 ms 12236 KB Output is correct
50 Correct 140 ms 12272 KB Output is correct
51 Correct 140 ms 12156 KB Output is correct
52 Correct 88 ms 10604 KB Output is correct
53 Correct 75 ms 9844 KB Output is correct