Submission #716967

# Submission time Handle Problem Language Result Execution time Memory
716967 2023-03-31T14:21:48 Z walterw Examination (JOI19_examination) C++17
100 / 100
211 ms 15056 KB
#include "bits/stdc++.h"

using namespace std;

void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
    cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
    while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
    return o >> a.first >> a.second;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
    return o << '(' << a.first << ", " << a.second << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
    bool is = false;
    for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
    return o << '}';
}

#ifdef local
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif

using ll = long long;

vector<array<int, 5>> queries;
vector<int> comp;

int ans[500005];

struct tree {
    int arr[500005];

    void add(int x) {
        for(; x < 500005; x += x & (-x)) {
            arr[x]++;
        }
    }

    int query(int lowerbound) {
        int tot = 0;
        for (int x = 500004; x > 0; x -= x & (-x)) {
            tot += arr[x];
        }

        int subtract = 0;
        for (int x = lowerbound - 1; x > 0; x -= x & (-x)) {
            subtract += arr[x];
        }

        return tot - subtract;
    }
} x, y;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);
    int n, q; cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        int s, t; cin >> s >> t;
        comp.push_back(s);
        comp.push_back(t);
        queries.push_back({s + t, s, t, 1, -1});
    }

    for (int i = 1; i <= q; i++) {
        int a, b, c; cin >> a >> b >> c;
        comp.push_back(a);
        comp.push_back(b);
        queries.push_back({max(c, a + b), a, b, -1, i});
    }

    sort(queries.begin(), queries.end(), [](array<int, 5> a, array<int, 5> b) {
        if (a[0] == b[0]) {
            return a[3] > b[3];
        }

        return a[0] > b[0];
    });

    sort(comp.begin(), comp.end());

    auto idx = [&](int a) {
        return lower_bound(comp.begin(), comp.end(), a) - comp.begin() + 1;
    };

    int total = 0;

    for (auto [a, b, c, d, e] : queries) {
        if (d == 1) {
            // add
            x.add(idx(b));
            y.add(idx(c));
            total++;
        } else {
            ans[e] = x.query(idx(b)) + y.query(idx(c)) - total;
        }
    }

    for (int i = 1; i <= q; i++) cout << ans[i] << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 6 ms 892 KB Output is correct
8 Correct 7 ms 852 KB Output is correct
9 Correct 5 ms 852 KB Output is correct
10 Correct 4 ms 848 KB Output is correct
11 Correct 4 ms 852 KB Output is correct
12 Correct 3 ms 852 KB Output is correct
13 Correct 7 ms 852 KB Output is correct
14 Correct 7 ms 852 KB Output is correct
15 Correct 5 ms 852 KB Output is correct
16 Correct 4 ms 856 KB Output is correct
17 Correct 4 ms 740 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 169 ms 10120 KB Output is correct
2 Correct 173 ms 12632 KB Output is correct
3 Correct 176 ms 12556 KB Output is correct
4 Correct 110 ms 9796 KB Output is correct
5 Correct 111 ms 9844 KB Output is correct
6 Correct 84 ms 8468 KB Output is correct
7 Correct 185 ms 12704 KB Output is correct
8 Correct 176 ms 12616 KB Output is correct
9 Correct 153 ms 12484 KB Output is correct
10 Correct 117 ms 9424 KB Output is correct
11 Correct 122 ms 9456 KB Output is correct
12 Correct 71 ms 7620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 169 ms 10120 KB Output is correct
2 Correct 173 ms 12632 KB Output is correct
3 Correct 176 ms 12556 KB Output is correct
4 Correct 110 ms 9796 KB Output is correct
5 Correct 111 ms 9844 KB Output is correct
6 Correct 84 ms 8468 KB Output is correct
7 Correct 185 ms 12704 KB Output is correct
8 Correct 176 ms 12616 KB Output is correct
9 Correct 153 ms 12484 KB Output is correct
10 Correct 117 ms 9424 KB Output is correct
11 Correct 122 ms 9456 KB Output is correct
12 Correct 71 ms 7620 KB Output is correct
13 Correct 192 ms 13056 KB Output is correct
14 Correct 178 ms 13036 KB Output is correct
15 Correct 168 ms 12736 KB Output is correct
16 Correct 123 ms 10220 KB Output is correct
17 Correct 119 ms 10180 KB Output is correct
18 Correct 79 ms 8344 KB Output is correct
19 Correct 179 ms 13116 KB Output is correct
20 Correct 211 ms 12988 KB Output is correct
21 Correct 170 ms 13092 KB Output is correct
22 Correct 110 ms 9424 KB Output is correct
23 Correct 108 ms 9368 KB Output is correct
24 Correct 66 ms 7684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 6 ms 892 KB Output is correct
8 Correct 7 ms 852 KB Output is correct
9 Correct 5 ms 852 KB Output is correct
10 Correct 4 ms 848 KB Output is correct
11 Correct 4 ms 852 KB Output is correct
12 Correct 3 ms 852 KB Output is correct
13 Correct 7 ms 852 KB Output is correct
14 Correct 7 ms 852 KB Output is correct
15 Correct 5 ms 852 KB Output is correct
16 Correct 4 ms 856 KB Output is correct
17 Correct 4 ms 740 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 169 ms 10120 KB Output is correct
20 Correct 173 ms 12632 KB Output is correct
21 Correct 176 ms 12556 KB Output is correct
22 Correct 110 ms 9796 KB Output is correct
23 Correct 111 ms 9844 KB Output is correct
24 Correct 84 ms 8468 KB Output is correct
25 Correct 185 ms 12704 KB Output is correct
26 Correct 176 ms 12616 KB Output is correct
27 Correct 153 ms 12484 KB Output is correct
28 Correct 117 ms 9424 KB Output is correct
29 Correct 122 ms 9456 KB Output is correct
30 Correct 71 ms 7620 KB Output is correct
31 Correct 192 ms 13056 KB Output is correct
32 Correct 178 ms 13036 KB Output is correct
33 Correct 168 ms 12736 KB Output is correct
34 Correct 123 ms 10220 KB Output is correct
35 Correct 119 ms 10180 KB Output is correct
36 Correct 79 ms 8344 KB Output is correct
37 Correct 179 ms 13116 KB Output is correct
38 Correct 211 ms 12988 KB Output is correct
39 Correct 170 ms 13092 KB Output is correct
40 Correct 110 ms 9424 KB Output is correct
41 Correct 108 ms 9368 KB Output is correct
42 Correct 66 ms 7684 KB Output is correct
43 Correct 185 ms 15000 KB Output is correct
44 Correct 185 ms 15056 KB Output is correct
45 Correct 179 ms 14984 KB Output is correct
46 Correct 128 ms 11236 KB Output is correct
47 Correct 137 ms 11380 KB Output is correct
48 Correct 83 ms 8152 KB Output is correct
49 Correct 178 ms 14920 KB Output is correct
50 Correct 195 ms 14916 KB Output is correct
51 Correct 176 ms 14784 KB Output is correct
52 Correct 122 ms 10860 KB Output is correct
53 Correct 127 ms 10164 KB Output is correct