Submission #1015269

# Submission time Handle Problem Language Result Execution time Memory
1015269 2024-07-06T08:13:00 Z aufan Examination (JOI19_examination) C++17
100 / 100
1242 ms 151912 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define fi first
#define se second
#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

struct node {
        ordered_multiset ms;
        int st, en;
        node *left, *right;

        void build(int start, int end) {
                st = start;
                en = end;

                if (st == en) {
                        return;
                }

                int md = (st + en) / 2;
                left = new node();
                right = new node();

                left->build(st, md);
                right->build(md + 1, en);
        }

        int query(int lf, int rg, int x) {
                if (st > rg || en < lf) return 0ll;
                if (lf <= st && en <= rg) return (int)ms.size() - ms.order_of_key(x);
                return left->query(lf, rg, x) + right->query(lf, rg, x);
        }

        void update(int id, int x) {
                if (st > id || en < id) return;
                ms.insert(x);
                if (st == en) return;

                left->update(id, x);
                right->update(id, x);
        }
} sg;

int32_t main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        int n, q;
        cin >> n >> q;

        vector<int> s(n), t(n);
        for (int i = 0; i < n; i++) cin >> s[i] >> t[i];

        vector<int> ord(n);
        iota(ord.begin(), ord.end(), 0);
        sort(ord.begin(), ord.end(), [&](int x, int y) {
                return s[x] + t[x] > s[y] + t[y];
        });

        vector<array<int, 4>> qr;
        for (int i = 0; i < q; i++) {
                int x, y, z;
                cin >> x >> y >> z;

                qr.push_back({x, y, z, i});
        }
        sort(qr.begin(), qr.end(), [&](auto x, auto y) {
                return x[2] > y[2];
        });

        vector<int> b;
        for (int i = 0; i < n; i++) b.push_back(s[i]);
        sort(b.begin(), b.end());
        b.erase(unique(b.begin(), b.end()), b.end());

        int m = (int)b.size();
        sg.build(1, m);

        auto get = [&](int x) {
                return lower_bound(b.begin(), b.end(), x) - b.begin();
        };

        int p = 0;
        vector<int> ans(q);
        for (auto [x, y, z, i] : qr) {
                while (p < n && s[ord[p]] + t[ord[p]] >= z) {
                        sg.update(get(s[ord[p]]) + 1, t[ord[p]]);
                        p += 1;
                }

                ans[i] = sg.query(get(x) + 1, m, y);
        }

        for (int i = 0; i < q; i++) cout << ans[i] << '\n';
        
        return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 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 10 ms 4004 KB Output is correct
8 Correct 10 ms 3928 KB Output is correct
9 Correct 10 ms 3928 KB Output is correct
10 Correct 9 ms 3932 KB Output is correct
11 Correct 4 ms 1628 KB Output is correct
12 Correct 4 ms 1372 KB Output is correct
13 Correct 15 ms 4036 KB Output is correct
14 Correct 10 ms 3932 KB Output is correct
15 Correct 10 ms 3932 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 12 ms 3996 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1242 ms 134324 KB Output is correct
2 Correct 1193 ms 134484 KB Output is correct
3 Correct 1200 ms 134596 KB Output is correct
4 Correct 711 ms 133840 KB Output is correct
5 Correct 244 ms 38268 KB Output is correct
6 Correct 199 ms 37572 KB Output is correct
7 Correct 1035 ms 134336 KB Output is correct
8 Correct 1031 ms 134504 KB Output is correct
9 Correct 961 ms 134340 KB Output is correct
10 Correct 96 ms 15804 KB Output is correct
11 Correct 533 ms 133704 KB Output is correct
12 Correct 85 ms 14788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1242 ms 134324 KB Output is correct
2 Correct 1193 ms 134484 KB Output is correct
3 Correct 1200 ms 134596 KB Output is correct
4 Correct 711 ms 133840 KB Output is correct
5 Correct 244 ms 38268 KB Output is correct
6 Correct 199 ms 37572 KB Output is correct
7 Correct 1035 ms 134336 KB Output is correct
8 Correct 1031 ms 134504 KB Output is correct
9 Correct 961 ms 134340 KB Output is correct
10 Correct 96 ms 15804 KB Output is correct
11 Correct 533 ms 133704 KB Output is correct
12 Correct 85 ms 14788 KB Output is correct
13 Correct 1060 ms 134788 KB Output is correct
14 Correct 1192 ms 134896 KB Output is correct
15 Correct 1130 ms 134340 KB Output is correct
16 Correct 628 ms 134088 KB Output is correct
17 Correct 227 ms 38480 KB Output is correct
18 Correct 201 ms 37500 KB Output is correct
19 Correct 971 ms 134836 KB Output is correct
20 Correct 1071 ms 135048 KB Output is correct
21 Correct 860 ms 134864 KB Output is correct
22 Correct 75 ms 15812 KB Output is correct
23 Correct 507 ms 133568 KB Output is correct
24 Correct 88 ms 14980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 10 ms 4004 KB Output is correct
8 Correct 10 ms 3928 KB Output is correct
9 Correct 10 ms 3928 KB Output is correct
10 Correct 9 ms 3932 KB Output is correct
11 Correct 4 ms 1628 KB Output is correct
12 Correct 4 ms 1372 KB Output is correct
13 Correct 15 ms 4036 KB Output is correct
14 Correct 10 ms 3932 KB Output is correct
15 Correct 10 ms 3932 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 12 ms 3996 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 1242 ms 134324 KB Output is correct
20 Correct 1193 ms 134484 KB Output is correct
21 Correct 1200 ms 134596 KB Output is correct
22 Correct 711 ms 133840 KB Output is correct
23 Correct 244 ms 38268 KB Output is correct
24 Correct 199 ms 37572 KB Output is correct
25 Correct 1035 ms 134336 KB Output is correct
26 Correct 1031 ms 134504 KB Output is correct
27 Correct 961 ms 134340 KB Output is correct
28 Correct 96 ms 15804 KB Output is correct
29 Correct 533 ms 133704 KB Output is correct
30 Correct 85 ms 14788 KB Output is correct
31 Correct 1060 ms 134788 KB Output is correct
32 Correct 1192 ms 134896 KB Output is correct
33 Correct 1130 ms 134340 KB Output is correct
34 Correct 628 ms 134088 KB Output is correct
35 Correct 227 ms 38480 KB Output is correct
36 Correct 201 ms 37500 KB Output is correct
37 Correct 971 ms 134836 KB Output is correct
38 Correct 1071 ms 135048 KB Output is correct
39 Correct 860 ms 134864 KB Output is correct
40 Correct 75 ms 15812 KB Output is correct
41 Correct 507 ms 133568 KB Output is correct
42 Correct 88 ms 14980 KB Output is correct
43 Correct 1060 ms 151764 KB Output is correct
44 Correct 1000 ms 151656 KB Output is correct
45 Correct 1194 ms 151688 KB Output is correct
46 Correct 734 ms 150100 KB Output is correct
47 Correct 211 ms 39616 KB Output is correct
48 Correct 178 ms 37388 KB Output is correct
49 Correct 996 ms 151912 KB Output is correct
50 Correct 865 ms 151768 KB Output is correct
51 Correct 888 ms 151636 KB Output is correct
52 Correct 112 ms 17300 KB Output is correct
53 Correct 525 ms 149188 KB Output is correct