Submission #871151

# Submission time Handle Problem Language Result Execution time Memory
871151 2023-11-10T05:11:00 Z LOLOLO Examination (JOI19_examination) C++14
100 / 100
567 ms 35580 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())
 
const int N = 8e5 + 100;
vector < vector <int>> st;
int f[N], ans[N];

void upd(int i, int x) {
    for (; i < N; i += i & (-i))
        f[i] += x;
}

int get(int i) {
    int s = 0;
    for (; i; i -= i & (-i))
        s += f[i];

    return s;
}

void dnc(int l, int r) {
    if (l == r)
        return;

    int m = (l + r) / 2;
    dnc(l, m);
    dnc(m + 1, r);

    vector < vector <int>> save;
    for (int i = l; i <= m; i++) {
        if (st[i][3] == -1) {
            save.pb({st[i][1], st[i][2], -1});
        }
    }

    for (int i = m + 1; i <= r; i++) {
        if (st[i][3] != -1) {
            save.pb({st[i][1], st[i][2], st[i][3]});
        }
    }

    sort(all(save));
    for (auto x : save) {
        if (x[2] == -1) {
            upd(x[1], 1);
        } else {
            ans[x[2]] += get(x[1]);
        }
    }

    for (auto x : save) {
        if (x[2] == -1) {
            upd(x[1], -1);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, q;
    cin >> n >> q;

    vector <int> coor;
    coor.pb((int)-4e9);

    for (int i = 1; i <= n; i++) {
        int s, t;
        cin >> s >> t;
        st.pb({-s, -t, -s - t, -1});
        coor.pb(-s);
        coor.pb(-t);
        coor.pb(-s - t);
    }

    for (int i = 1; i <= q; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a = -a, b = -b, c = -c;
        coor.pb(a), coor.pb(b), coor.pb(c);
        st.pb({a, b, c, i});
    }

    sort(all(coor));
    uniquev(coor);

    for (auto &x : st) {
        for (int j = 0; j < 3; j++) {
            x[j] = lower_bound(all(coor), x[j]) - coor.begin();
        }
    }

    sort(all(st));
    dnc(0, n + q - 1);

    for (int i = 1; i <= q; i++) {
        cout << ans[i] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 12 ms 3112 KB Output is correct
8 Correct 11 ms 1116 KB Output is correct
9 Correct 12 ms 3164 KB Output is correct
10 Correct 11 ms 1116 KB Output is correct
11 Correct 10 ms 3320 KB Output is correct
12 Correct 8 ms 3160 KB Output is correct
13 Correct 11 ms 1216 KB Output is correct
14 Correct 11 ms 3164 KB Output is correct
15 Correct 10 ms 1116 KB Output is correct
16 Correct 9 ms 988 KB Output is correct
17 Correct 10 ms 3160 KB Output is correct
18 Correct 10 ms 1184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 507 ms 27848 KB Output is correct
2 Correct 509 ms 29664 KB Output is correct
3 Correct 508 ms 27360 KB Output is correct
4 Correct 488 ms 26596 KB Output is correct
5 Correct 415 ms 27212 KB Output is correct
6 Correct 342 ms 28888 KB Output is correct
7 Correct 492 ms 33392 KB Output is correct
8 Correct 491 ms 28896 KB Output is correct
9 Correct 477 ms 34776 KB Output is correct
10 Correct 366 ms 24540 KB Output is correct
11 Correct 475 ms 25316 KB Output is correct
12 Correct 301 ms 22488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 507 ms 27848 KB Output is correct
2 Correct 509 ms 29664 KB Output is correct
3 Correct 508 ms 27360 KB Output is correct
4 Correct 488 ms 26596 KB Output is correct
5 Correct 415 ms 27212 KB Output is correct
6 Correct 342 ms 28888 KB Output is correct
7 Correct 492 ms 33392 KB Output is correct
8 Correct 491 ms 28896 KB Output is correct
9 Correct 477 ms 34776 KB Output is correct
10 Correct 366 ms 24540 KB Output is correct
11 Correct 475 ms 25316 KB Output is correct
12 Correct 301 ms 22488 KB Output is correct
13 Correct 547 ms 28436 KB Output is correct
14 Correct 522 ms 29580 KB Output is correct
15 Correct 505 ms 29896 KB Output is correct
16 Correct 529 ms 28512 KB Output is correct
17 Correct 429 ms 26848 KB Output is correct
18 Correct 367 ms 26088 KB Output is correct
19 Correct 541 ms 30804 KB Output is correct
20 Correct 541 ms 30800 KB Output is correct
21 Correct 530 ms 32588 KB Output is correct
22 Correct 373 ms 24672 KB Output is correct
23 Correct 463 ms 27560 KB Output is correct
24 Correct 303 ms 22124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 12 ms 3112 KB Output is correct
8 Correct 11 ms 1116 KB Output is correct
9 Correct 12 ms 3164 KB Output is correct
10 Correct 11 ms 1116 KB Output is correct
11 Correct 10 ms 3320 KB Output is correct
12 Correct 8 ms 3160 KB Output is correct
13 Correct 11 ms 1216 KB Output is correct
14 Correct 11 ms 3164 KB Output is correct
15 Correct 10 ms 1116 KB Output is correct
16 Correct 9 ms 988 KB Output is correct
17 Correct 10 ms 3160 KB Output is correct
18 Correct 10 ms 1184 KB Output is correct
19 Correct 507 ms 27848 KB Output is correct
20 Correct 509 ms 29664 KB Output is correct
21 Correct 508 ms 27360 KB Output is correct
22 Correct 488 ms 26596 KB Output is correct
23 Correct 415 ms 27212 KB Output is correct
24 Correct 342 ms 28888 KB Output is correct
25 Correct 492 ms 33392 KB Output is correct
26 Correct 491 ms 28896 KB Output is correct
27 Correct 477 ms 34776 KB Output is correct
28 Correct 366 ms 24540 KB Output is correct
29 Correct 475 ms 25316 KB Output is correct
30 Correct 301 ms 22488 KB Output is correct
31 Correct 547 ms 28436 KB Output is correct
32 Correct 522 ms 29580 KB Output is correct
33 Correct 505 ms 29896 KB Output is correct
34 Correct 529 ms 28512 KB Output is correct
35 Correct 429 ms 26848 KB Output is correct
36 Correct 367 ms 26088 KB Output is correct
37 Correct 541 ms 30804 KB Output is correct
38 Correct 541 ms 30800 KB Output is correct
39 Correct 530 ms 32588 KB Output is correct
40 Correct 373 ms 24672 KB Output is correct
41 Correct 463 ms 27560 KB Output is correct
42 Correct 303 ms 22124 KB Output is correct
43 Correct 567 ms 33572 KB Output is correct
44 Correct 553 ms 30144 KB Output is correct
45 Correct 561 ms 32224 KB Output is correct
46 Correct 531 ms 30024 KB Output is correct
47 Correct 444 ms 28572 KB Output is correct
48 Correct 354 ms 23520 KB Output is correct
49 Correct 546 ms 35580 KB Output is correct
50 Correct 533 ms 31620 KB Output is correct
51 Correct 538 ms 35148 KB Output is correct
52 Correct 407 ms 28248 KB Output is correct
53 Correct 455 ms 27872 KB Output is correct