Submission #512939

# Submission time Handle Problem Language Result Execution time Memory
512939 2022-01-16T20:15:34 Z couplefire Examination (JOI19_examination) C++17
100 / 100
403 ms 7088 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 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 8 ms 460 KB Output is correct
8 Correct 8 ms 572 KB Output is correct
9 Correct 9 ms 460 KB Output is correct
10 Correct 7 ms 548 KB Output is correct
11 Correct 7 ms 460 KB Output is correct
12 Correct 6 ms 556 KB Output is correct
13 Correct 12 ms 460 KB Output is correct
14 Correct 7 ms 460 KB Output is correct
15 Correct 8 ms 460 KB Output is correct
16 Correct 5 ms 460 KB Output is correct
17 Correct 7 ms 460 KB Output is correct
18 Correct 4 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 356 ms 6428 KB Output is correct
2 Correct 372 ms 6672 KB Output is correct
3 Correct 367 ms 6456 KB Output is correct
4 Correct 284 ms 6264 KB Output is correct
5 Correct 247 ms 6480 KB Output is correct
6 Correct 211 ms 6144 KB Output is correct
7 Correct 352 ms 6640 KB Output is correct
8 Correct 345 ms 6428 KB Output is correct
9 Correct 339 ms 6448 KB Output is correct
10 Correct 207 ms 6264 KB Output is correct
11 Correct 262 ms 6064 KB Output is correct
12 Correct 196 ms 5936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 356 ms 6428 KB Output is correct
2 Correct 372 ms 6672 KB Output is correct
3 Correct 367 ms 6456 KB Output is correct
4 Correct 284 ms 6264 KB Output is correct
5 Correct 247 ms 6480 KB Output is correct
6 Correct 211 ms 6144 KB Output is correct
7 Correct 352 ms 6640 KB Output is correct
8 Correct 345 ms 6428 KB Output is correct
9 Correct 339 ms 6448 KB Output is correct
10 Correct 207 ms 6264 KB Output is correct
11 Correct 262 ms 6064 KB Output is correct
12 Correct 196 ms 5936 KB Output is correct
13 Correct 379 ms 6500 KB Output is correct
14 Correct 389 ms 6576 KB Output is correct
15 Correct 356 ms 6432 KB Output is correct
16 Correct 330 ms 6180 KB Output is correct
17 Correct 280 ms 6452 KB Output is correct
18 Correct 223 ms 6188 KB Output is correct
19 Correct 403 ms 6500 KB Output is correct
20 Correct 383 ms 6456 KB Output is correct
21 Correct 378 ms 6500 KB Output is correct
22 Correct 203 ms 6364 KB Output is correct
23 Correct 266 ms 6132 KB Output is correct
24 Correct 187 ms 5804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 8 ms 460 KB Output is correct
8 Correct 8 ms 572 KB Output is correct
9 Correct 9 ms 460 KB Output is correct
10 Correct 7 ms 548 KB Output is correct
11 Correct 7 ms 460 KB Output is correct
12 Correct 6 ms 556 KB Output is correct
13 Correct 12 ms 460 KB Output is correct
14 Correct 7 ms 460 KB Output is correct
15 Correct 8 ms 460 KB Output is correct
16 Correct 5 ms 460 KB Output is correct
17 Correct 7 ms 460 KB Output is correct
18 Correct 4 ms 460 KB Output is correct
19 Correct 356 ms 6428 KB Output is correct
20 Correct 372 ms 6672 KB Output is correct
21 Correct 367 ms 6456 KB Output is correct
22 Correct 284 ms 6264 KB Output is correct
23 Correct 247 ms 6480 KB Output is correct
24 Correct 211 ms 6144 KB Output is correct
25 Correct 352 ms 6640 KB Output is correct
26 Correct 345 ms 6428 KB Output is correct
27 Correct 339 ms 6448 KB Output is correct
28 Correct 207 ms 6264 KB Output is correct
29 Correct 262 ms 6064 KB Output is correct
30 Correct 196 ms 5936 KB Output is correct
31 Correct 379 ms 6500 KB Output is correct
32 Correct 389 ms 6576 KB Output is correct
33 Correct 356 ms 6432 KB Output is correct
34 Correct 330 ms 6180 KB Output is correct
35 Correct 280 ms 6452 KB Output is correct
36 Correct 223 ms 6188 KB Output is correct
37 Correct 403 ms 6500 KB Output is correct
38 Correct 383 ms 6456 KB Output is correct
39 Correct 378 ms 6500 KB Output is correct
40 Correct 203 ms 6364 KB Output is correct
41 Correct 266 ms 6132 KB Output is correct
42 Correct 187 ms 5804 KB Output is correct
43 Correct 391 ms 6876 KB Output is correct
44 Correct 388 ms 6908 KB Output is correct
45 Correct 393 ms 6972 KB Output is correct
46 Correct 320 ms 6268 KB Output is correct
47 Correct 280 ms 6900 KB Output is correct
48 Correct 223 ms 5884 KB Output is correct
49 Correct 359 ms 6984 KB Output is correct
50 Correct 386 ms 7088 KB Output is correct
51 Correct 391 ms 6956 KB Output is correct
52 Correct 273 ms 6736 KB Output is correct
53 Correct 260 ms 6040 KB Output is correct