답안 #888645

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
888645 2023-12-18T04:58:39 Z box Examination (JOI19_examination) C++17
100 / 100
299 ms 15276 KB
#include <bits/stdc++.h>
using namespace std;

#define ar array
#define sz(v) int(std::size(v))
using i64 = long long;
using pii = pair<int, int>;

const int N = 1e5, Q = 1e5;

int n, q;
int x[N], y[N], z[N];
int ans[Q];

vector<int> sor(int *a) {
    vector v(a, a + n);
    sort(begin(v), end(v));
    v.erase(unique(begin(v), end(v)), end(v));
    return v;
}

int ft[N];

void add(int i, int x) {
    while (i < n) {
        ft[i] += x;
        i |= i + 1;
    }
}

int sum(int i) {
    int x = 0;
    while (i >= 0) {
        x += ft[i];
        i &= i + 1, i--;
    }
    return x;
}

vector<ar<int, 4>> events;

void rec(int l, int r) {
    if (l < r) {
        int m = (l + r) / 2;
        rec(l, m);
        rec(m + 1, r);
        vector<ar<int, 2>> one;
        for (int i = l; i <= m; i++) if (events[i][3] == -1) one.push_back({events[i][1], events[i][2]});
        vector<ar<int, 3>> two;
        for (int i = m + 1; i <= r; i++) if (~events[i][3]) two.push_back({events[i][1], events[i][2], events[i][3]});
        sort(begin(one), end(one));
        sort(begin(two), end(two));
        int p = 0;
        for (auto [b, c, h] : two) {
            while (p < sz(one) && b >= one[p][0]) {
                auto [y, z] = one[p++];
                add(z, 1);
            }
            ans[h] += sum(c);
        }
        while (p > 0) {
            auto [y, z] = one[--p];
            add(z, -1);
        }
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL);
    cin >> n >> q;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        z[i] = x[i] + y[i];
    }
    auto xx = sor(x);
    auto yy = sor(y);
    auto zz = sor(z);
    for (int i = 0; i < n; i++) {
        x[i] = lower_bound(begin(xx), end(xx), x[i]) - begin(xx);
        y[i] = lower_bound(begin(yy), end(yy), y[i]) - begin(yy);
        z[i] = lower_bound(begin(zz), end(zz), z[i]) - begin(zz);
        events.push_back({x[i], y[i], z[i], -1});
    }
    for (int h = 0; h < q; h++) {
        int a, b, c;
        cin >> a >> b >> c;
        a = lower_bound(begin(xx), end(xx), a) - begin(xx);
        b = lower_bound(begin(yy), end(yy), b) - begin(yy);
        c = lower_bound(begin(zz), end(zz), c) - begin(zz);
        if (a < sz(xx) && b < sz(yy) && c < sz(zz)) events.push_back({a, b, c, h});
    }
    for (auto &[x, y, z, t] : events) {
        x = sz(xx) - x - 1;
        y = sz(yy) - y - 1;
        z = sz(zz) - z - 1;
    }
    sort(begin(events), end(events));
    rec(0, sz(events) - 1);
    for (int h = 0; h < q; h++) cout << ans[h] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 6 ms 736 KB Output is correct
8 Correct 6 ms 860 KB Output is correct
9 Correct 6 ms 860 KB Output is correct
10 Correct 7 ms 860 KB Output is correct
11 Correct 5 ms 860 KB Output is correct
12 Correct 5 ms 732 KB Output is correct
13 Correct 6 ms 860 KB Output is correct
14 Correct 6 ms 704 KB Output is correct
15 Correct 6 ms 860 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 4 ms 856 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 276 ms 12824 KB Output is correct
2 Correct 267 ms 11972 KB Output is correct
3 Correct 268 ms 11468 KB Output is correct
4 Correct 268 ms 11320 KB Output is correct
5 Correct 207 ms 10848 KB Output is correct
6 Correct 153 ms 10068 KB Output is correct
7 Correct 246 ms 12840 KB Output is correct
8 Correct 261 ms 11684 KB Output is correct
9 Correct 247 ms 12516 KB Output is correct
10 Correct 167 ms 9924 KB Output is correct
11 Correct 182 ms 10320 KB Output is correct
12 Correct 68 ms 6860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 276 ms 12824 KB Output is correct
2 Correct 267 ms 11972 KB Output is correct
3 Correct 268 ms 11468 KB Output is correct
4 Correct 268 ms 11320 KB Output is correct
5 Correct 207 ms 10848 KB Output is correct
6 Correct 153 ms 10068 KB Output is correct
7 Correct 246 ms 12840 KB Output is correct
8 Correct 261 ms 11684 KB Output is correct
9 Correct 247 ms 12516 KB Output is correct
10 Correct 167 ms 9924 KB Output is correct
11 Correct 182 ms 10320 KB Output is correct
12 Correct 68 ms 6860 KB Output is correct
13 Correct 287 ms 11968 KB Output is correct
14 Correct 290 ms 12712 KB Output is correct
15 Correct 265 ms 12420 KB Output is correct
16 Correct 279 ms 11200 KB Output is correct
17 Correct 225 ms 11208 KB Output is correct
18 Correct 152 ms 10696 KB Output is correct
19 Correct 291 ms 12492 KB Output is correct
20 Correct 285 ms 12736 KB Output is correct
21 Correct 289 ms 12752 KB Output is correct
22 Correct 163 ms 9804 KB Output is correct
23 Correct 183 ms 10516 KB Output is correct
24 Correct 68 ms 6860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 6 ms 736 KB Output is correct
8 Correct 6 ms 860 KB Output is correct
9 Correct 6 ms 860 KB Output is correct
10 Correct 7 ms 860 KB Output is correct
11 Correct 5 ms 860 KB Output is correct
12 Correct 5 ms 732 KB Output is correct
13 Correct 6 ms 860 KB Output is correct
14 Correct 6 ms 704 KB Output is correct
15 Correct 6 ms 860 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 4 ms 856 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
19 Correct 276 ms 12824 KB Output is correct
20 Correct 267 ms 11972 KB Output is correct
21 Correct 268 ms 11468 KB Output is correct
22 Correct 268 ms 11320 KB Output is correct
23 Correct 207 ms 10848 KB Output is correct
24 Correct 153 ms 10068 KB Output is correct
25 Correct 246 ms 12840 KB Output is correct
26 Correct 261 ms 11684 KB Output is correct
27 Correct 247 ms 12516 KB Output is correct
28 Correct 167 ms 9924 KB Output is correct
29 Correct 182 ms 10320 KB Output is correct
30 Correct 68 ms 6860 KB Output is correct
31 Correct 287 ms 11968 KB Output is correct
32 Correct 290 ms 12712 KB Output is correct
33 Correct 265 ms 12420 KB Output is correct
34 Correct 279 ms 11200 KB Output is correct
35 Correct 225 ms 11208 KB Output is correct
36 Correct 152 ms 10696 KB Output is correct
37 Correct 291 ms 12492 KB Output is correct
38 Correct 285 ms 12736 KB Output is correct
39 Correct 289 ms 12752 KB Output is correct
40 Correct 163 ms 9804 KB Output is correct
41 Correct 183 ms 10516 KB Output is correct
42 Correct 68 ms 6860 KB Output is correct
43 Correct 299 ms 14088 KB Output is correct
44 Correct 297 ms 14268 KB Output is correct
45 Correct 298 ms 14500 KB Output is correct
46 Correct 283 ms 12480 KB Output is correct
47 Correct 236 ms 12356 KB Output is correct
48 Correct 118 ms 9732 KB Output is correct
49 Correct 280 ms 14920 KB Output is correct
50 Correct 298 ms 14904 KB Output is correct
51 Correct 270 ms 15276 KB Output is correct
52 Correct 178 ms 11560 KB Output is correct
53 Correct 174 ms 10168 KB Output is correct