Submission #322592

# Submission time Handle Problem Language Result Execution time Memory
322592 2020-11-15T01:59:56 Z arbor Examination (JOI19_examination) C++14
100 / 100
506 ms 11916 KB
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 2e5 + 5;
int N, Q;
struct Point {
    int a, b, c, i;
} p[MN];
int b[MN], ans[MN];
void upd(int i, int v) {
    for (; i < MN; i += i & -i) b[i] += v;
}
int get(int i) {
    int r = 0;
    for (; i; i -= i & -i) r += b[i];
    return r;
}
void cdq(int l, int r) {
    if (l >= r) return;
    int m = (l + r) / 2;
    cdq(l, m), cdq(m + 1, r);
    sort(p + l, p + r + 1, [](Point x, Point y) {
        return x.a == y.a ? x.i < y.i : x.a > y.a;
    });
    for (int i = l; i <= r; i++) {
        if (p[i].c <= m && !p[i].i) upd(p[i].b, 1);
        if (p[i].c > m && p[i].i) ans[p[i].i] += get(2e5) - get(p[i].b - 1);
    }
    for (int i = l; i <= r; i++)
        if (p[i].c <= m && !p[i].i) upd(p[i].b, -1);
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> N >> Q;
    vector<int> ca, cb;
    for (int i = 1; i <= N; i++) {
        cin >> p[i].a >> p[i].b;
        p[i].c = p[i].a + p[i].b;
        ca.push_back(p[i].a);
        cb.push_back(p[i].b);
    }
    for (int i = N + 1; i <= N + Q; i++) {
        cin >> p[i].a >> p[i].b >> p[i].c;
        p[i].i = i - N;
        ca.push_back(p[i].a);
        cb.push_back(p[i].b);
    }
    sort(p + 1, p + 1 + N + Q, [](Point x, Point y) {
       return x.c == y.c ? x.i < y.i : x.c > y.c;
    });
    sort(all(ca)), sort(all(cb));
    ca.erase(unique(all(ca)), ca.end());
    cb.erase(unique(all(cb)), cb.end());
    for (int i = 1; i <= N + Q; i++) {
        p[i].a = lower_bound(all(ca), p[i].a) - ca.begin() + 1;
        p[i].b = lower_bound(all(cb), p[i].b) - cb.begin() + 1;
        p[i].c = i;
    }
    cdq(1, N + Q);
    for (int i = 1; i <= Q; i++) cout << ans[i] << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 10 ms 620 KB Output is correct
8 Correct 11 ms 620 KB Output is correct
9 Correct 10 ms 620 KB Output is correct
10 Correct 9 ms 620 KB Output is correct
11 Correct 9 ms 620 KB Output is correct
12 Correct 8 ms 620 KB Output is correct
13 Correct 10 ms 748 KB Output is correct
14 Correct 10 ms 748 KB Output is correct
15 Correct 10 ms 748 KB Output is correct
16 Correct 7 ms 748 KB Output is correct
17 Correct 9 ms 748 KB Output is correct
18 Correct 6 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 459 ms 6616 KB Output is correct
2 Correct 472 ms 9168 KB Output is correct
3 Correct 466 ms 9176 KB Output is correct
4 Correct 362 ms 8084 KB Output is correct
5 Correct 314 ms 8408 KB Output is correct
6 Correct 281 ms 7384 KB Output is correct
7 Correct 440 ms 9048 KB Output is correct
8 Correct 442 ms 9048 KB Output is correct
9 Correct 448 ms 8924 KB Output is correct
10 Correct 267 ms 8360 KB Output is correct
11 Correct 346 ms 7880 KB Output is correct
12 Correct 251 ms 6872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 459 ms 6616 KB Output is correct
2 Correct 472 ms 9168 KB Output is correct
3 Correct 466 ms 9176 KB Output is correct
4 Correct 362 ms 8084 KB Output is correct
5 Correct 314 ms 8408 KB Output is correct
6 Correct 281 ms 7384 KB Output is correct
7 Correct 440 ms 9048 KB Output is correct
8 Correct 442 ms 9048 KB Output is correct
9 Correct 448 ms 8924 KB Output is correct
10 Correct 267 ms 8360 KB Output is correct
11 Correct 346 ms 7880 KB Output is correct
12 Correct 251 ms 6872 KB Output is correct
13 Correct 484 ms 9664 KB Output is correct
14 Correct 485 ms 9560 KB Output is correct
15 Correct 453 ms 9048 KB Output is correct
16 Correct 417 ms 8408 KB Output is correct
17 Correct 374 ms 8920 KB Output is correct
18 Correct 301 ms 7384 KB Output is correct
19 Correct 490 ms 9688 KB Output is correct
20 Correct 506 ms 9560 KB Output is correct
21 Correct 464 ms 9560 KB Output is correct
22 Correct 266 ms 8284 KB Output is correct
23 Correct 357 ms 7896 KB Output is correct
24 Correct 253 ms 7000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 10 ms 620 KB Output is correct
8 Correct 11 ms 620 KB Output is correct
9 Correct 10 ms 620 KB Output is correct
10 Correct 9 ms 620 KB Output is correct
11 Correct 9 ms 620 KB Output is correct
12 Correct 8 ms 620 KB Output is correct
13 Correct 10 ms 748 KB Output is correct
14 Correct 10 ms 748 KB Output is correct
15 Correct 10 ms 748 KB Output is correct
16 Correct 7 ms 748 KB Output is correct
17 Correct 9 ms 748 KB Output is correct
18 Correct 6 ms 620 KB Output is correct
19 Correct 459 ms 6616 KB Output is correct
20 Correct 472 ms 9168 KB Output is correct
21 Correct 466 ms 9176 KB Output is correct
22 Correct 362 ms 8084 KB Output is correct
23 Correct 314 ms 8408 KB Output is correct
24 Correct 281 ms 7384 KB Output is correct
25 Correct 440 ms 9048 KB Output is correct
26 Correct 442 ms 9048 KB Output is correct
27 Correct 448 ms 8924 KB Output is correct
28 Correct 267 ms 8360 KB Output is correct
29 Correct 346 ms 7880 KB Output is correct
30 Correct 251 ms 6872 KB Output is correct
31 Correct 484 ms 9664 KB Output is correct
32 Correct 485 ms 9560 KB Output is correct
33 Correct 453 ms 9048 KB Output is correct
34 Correct 417 ms 8408 KB Output is correct
35 Correct 374 ms 8920 KB Output is correct
36 Correct 301 ms 7384 KB Output is correct
37 Correct 490 ms 9688 KB Output is correct
38 Correct 506 ms 9560 KB Output is correct
39 Correct 464 ms 9560 KB Output is correct
40 Correct 266 ms 8284 KB Output is correct
41 Correct 357 ms 7896 KB Output is correct
42 Correct 253 ms 7000 KB Output is correct
43 Correct 501 ms 11908 KB Output is correct
44 Correct 502 ms 11864 KB Output is correct
45 Correct 503 ms 11864 KB Output is correct
46 Correct 424 ms 9688 KB Output is correct
47 Correct 369 ms 10384 KB Output is correct
48 Correct 298 ms 7128 KB Output is correct
49 Correct 464 ms 11736 KB Output is correct
50 Correct 497 ms 11916 KB Output is correct
51 Correct 461 ms 11736 KB Output is correct
52 Correct 352 ms 10328 KB Output is correct
53 Correct 343 ms 8664 KB Output is correct