Submission #561741

# Submission time Handle Problem Language Result Execution time Memory
561741 2022-05-13T12:29:41 Z timreizin Examination (JOI19_examination) C++17
100 / 100
2193 ms 201844 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

struct score
{
    int s, t, sum;

    score(int s = 0, int t = 0, int sum = 0) : s(s), t(t), sum(sum)
    {

    }
};

struct query
{
    int i;
    int a, b, c;

    query(int i = 0, int a = 0, int b = 0, int c = 0) : i(i), a(a), b(b), c(c)
    {

    }
};

using ordered_set = tree<pair<int, int>, null_type, greater<>, rb_tree_tag, tree_order_statistics_node_update>;

struct segtree
{
    int n;
    vector<ordered_set> tree;

    segtree(int n = 0) : n(n)
    {
        tree.resize(4 * n + 5);
    }
//count >=b in [a, b]
    int get(int a, int b, int val, int l, int r, int v)
    {
        if (a > r || b < l) return 0;
        if (a == l && b == r) return tree[v].order_of_key({val, -1});
        int m = (l + r) >> 1;
        return get(a, min(b, m), val, l, m, v << 1) + get(max(a, m + 1), b, val, m + 1, r, v << 1 | 1);
    }
    //>= sum, >= b
    int get(int sum, int b)
    {
        return get(sum, n - 1, b, 0, n - 1, 1);
    }

    void update(int p, int val, int l, int r, int v)
    {
        if (l > r) return;
        tree[v].insert({val, tree[v].size()});
        if (l == r) return;
        int m = (l + r) >> 1;
        if (p <= m) update(p, val, l, m, v << 1);
        else update(p, val, m + 1, r, v << 1 | 1);
    }

    void update(int sum, int b)
    {
        update(sum, b, 0, n - 1, 1);
    }
};

int main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n, q;
    cin >> n >> q;
    vector<score> st(n);
    vector<int> compress;
    for (auto &i : st)
    {
        cin >> i.s >> i.t;
        i.sum = i.s + i.t;
        compress.push_back(i.sum);
    }
    vector<query> queries(q);
    for (int i = 0; i < q; ++i)
    {
        cin >> queries[i].a >> queries[i].b >> queries[i].c;
        queries[i].i = i;
        compress.push_back(queries[i].c);
    }
    sort(compress.begin(), compress.end());
    compress.erase(unique(compress.begin(), compress.end()), compress.end());
    for (auto &i : st) i.sum = distance(compress.begin(), lower_bound(compress.begin(), compress.end(), i.sum));
    for (auto &i : queries) i.c = distance(compress.begin(), lower_bound(compress.begin(), compress.end(), i.c));
    int mx = compress.size();
    sort(st.begin(), st.end(), [](auto a, auto b){ return a.s > b.s; });
    sort(queries.begin(), queries.end(), [](auto a, auto b){ return a.a > b.a; });
    vector<int> res(q);
    int ind = 0;
    segtree help(mx);
    for (auto i : queries)
    {
        while (ind < n && st[ind].s >= i.a)
        {
            //update
            help.update(st[ind].sum, st[ind].t);
            ++ind;
        }
        res[i.i] = help.get(i.c, i.b);
    }
    for (int i : res) cout << i << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 21 ms 5292 KB Output is correct
8 Correct 17 ms 5332 KB Output is correct
9 Correct 19 ms 5324 KB Output is correct
10 Correct 15 ms 5328 KB Output is correct
11 Correct 14 ms 5356 KB Output is correct
12 Correct 7 ms 1492 KB Output is correct
13 Correct 12 ms 4052 KB Output is correct
14 Correct 13 ms 4052 KB Output is correct
15 Correct 14 ms 4052 KB Output is correct
16 Correct 15 ms 3924 KB Output is correct
17 Correct 14 ms 5344 KB Output is correct
18 Correct 5 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1772 ms 142732 KB Output is correct
2 Correct 1731 ms 142820 KB Output is correct
3 Correct 1722 ms 142792 KB Output is correct
4 Correct 871 ms 136548 KB Output is correct
5 Correct 1313 ms 136544 KB Output is correct
6 Correct 352 ms 39988 KB Output is correct
7 Correct 1720 ms 142796 KB Output is correct
8 Correct 1632 ms 142820 KB Output is correct
9 Correct 1647 ms 142596 KB Output is correct
10 Correct 1322 ms 136252 KB Output is correct
11 Correct 756 ms 136396 KB Output is correct
12 Correct 94 ms 11596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1772 ms 142732 KB Output is correct
2 Correct 1731 ms 142820 KB Output is correct
3 Correct 1722 ms 142792 KB Output is correct
4 Correct 871 ms 136548 KB Output is correct
5 Correct 1313 ms 136544 KB Output is correct
6 Correct 352 ms 39988 KB Output is correct
7 Correct 1720 ms 142796 KB Output is correct
8 Correct 1632 ms 142820 KB Output is correct
9 Correct 1647 ms 142596 KB Output is correct
10 Correct 1322 ms 136252 KB Output is correct
11 Correct 756 ms 136396 KB Output is correct
12 Correct 94 ms 11596 KB Output is correct
13 Correct 2193 ms 166288 KB Output is correct
14 Correct 2008 ms 162092 KB Output is correct
15 Correct 1776 ms 142752 KB Output is correct
16 Correct 1279 ms 148956 KB Output is correct
17 Correct 1695 ms 149012 KB Output is correct
18 Correct 438 ms 40008 KB Output is correct
19 Correct 2149 ms 166348 KB Output is correct
20 Correct 2148 ms 163100 KB Output is correct
21 Correct 2117 ms 166452 KB Output is correct
22 Correct 1300 ms 136408 KB Output is correct
23 Correct 761 ms 136284 KB Output is correct
24 Correct 117 ms 11616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 21 ms 5292 KB Output is correct
8 Correct 17 ms 5332 KB Output is correct
9 Correct 19 ms 5324 KB Output is correct
10 Correct 15 ms 5328 KB Output is correct
11 Correct 14 ms 5356 KB Output is correct
12 Correct 7 ms 1492 KB Output is correct
13 Correct 12 ms 4052 KB Output is correct
14 Correct 13 ms 4052 KB Output is correct
15 Correct 14 ms 4052 KB Output is correct
16 Correct 15 ms 3924 KB Output is correct
17 Correct 14 ms 5344 KB Output is correct
18 Correct 5 ms 1108 KB Output is correct
19 Correct 1772 ms 142732 KB Output is correct
20 Correct 1731 ms 142820 KB Output is correct
21 Correct 1722 ms 142792 KB Output is correct
22 Correct 871 ms 136548 KB Output is correct
23 Correct 1313 ms 136544 KB Output is correct
24 Correct 352 ms 39988 KB Output is correct
25 Correct 1720 ms 142796 KB Output is correct
26 Correct 1632 ms 142820 KB Output is correct
27 Correct 1647 ms 142596 KB Output is correct
28 Correct 1322 ms 136252 KB Output is correct
29 Correct 756 ms 136396 KB Output is correct
30 Correct 94 ms 11596 KB Output is correct
31 Correct 2193 ms 166288 KB Output is correct
32 Correct 2008 ms 162092 KB Output is correct
33 Correct 1776 ms 142752 KB Output is correct
34 Correct 1279 ms 148956 KB Output is correct
35 Correct 1695 ms 149012 KB Output is correct
36 Correct 438 ms 40008 KB Output is correct
37 Correct 2149 ms 166348 KB Output is correct
38 Correct 2148 ms 163100 KB Output is correct
39 Correct 2117 ms 166452 KB Output is correct
40 Correct 1300 ms 136408 KB Output is correct
41 Correct 761 ms 136284 KB Output is correct
42 Correct 117 ms 11616 KB Output is correct
43 Correct 2157 ms 201844 KB Output is correct
44 Correct 2154 ms 201808 KB Output is correct
45 Correct 2135 ms 201824 KB Output is correct
46 Correct 1375 ms 200176 KB Output is correct
47 Correct 1764 ms 200288 KB Output is correct
48 Correct 448 ms 48100 KB Output is correct
49 Correct 2115 ms 201752 KB Output is correct
50 Correct 1980 ms 201692 KB Output is correct
51 Correct 2041 ms 201668 KB Output is correct
52 Correct 1572 ms 200108 KB Output is correct
53 Correct 787 ms 155504 KB Output is correct