답안 #216208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
216208 2020-03-26T21:44:51 Z DS007 Examination (JOI19_examination) C++14
100 / 100
2233 ms 161440 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define mid (l + r) / 2
#define child v * 2
#define index_set tree<pair<int, int>, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>

struct query {
    int x, y, z, i, ans;

    query() {
        x = y = z = i = ans = -1;
    }
};

const int N = 1e5 + 5;
int a[N], b[N];
pair<int, int> s[N];
query qry[N];
int n, q;

index_set t[N * 4];
multimap<int, int> m;

void update(int v, int l, int r, int tl, int val) {
    t[v].insert({val, tl});
    if (l == r && tl == l)
        return;
    else if (tl <= mid)
        update(child, l, mid, tl, val);
    else
        update(child + 1, mid + 1, r, tl, val);
}

int query(int v, int l, int r, int tl, int tr, int val) {
    if (tl > tr)
        return 0;
    else if (l == tl && r == tr)
        return t[v].size() - t[v].order_of_key({val, -1});
    return query(child, l, mid, tl, min(mid, tr), val) + query(child + 1, mid + 1, r, max(mid + 1, tl), tr, val);
}

void solveTestCase() {
    cin >> n >> q;
    for (int i = 0; i < n; i++)
        cin >> s[i].first >> s[i].second, a[i] = s[i].first, b[i] = s[i].second;
    for (int i = 0; i < q; i++)
        cin >> qry[i].x >> qry[i].y >> qry[i].z, qry[i].i = i;

    sort(a, a + n, greater<>());
    sort(b, b + n);
    sort(s, s + n, greater<>());

    sort(qry, qry + q, [](auto &q1, auto &q2) {
        return q1.x > q2.x;
    });

    for (int i = 0; i < n; i++)
        m.insert({b[i], i});

    for (int i = 0, p = 0; i < q; i++) {
        while (p != n && s[p].first >= qry[i].x) {
            auto itr = m.find(s[p].second);
            update(1, 0, n - 1, itr->second, s[p].first + s[p].second);
            m.erase(itr);
            p++;
        }

        int tl = lower_bound(b, b + n, qry[i].y) - b;
        qry[i].ans = query(1, 0, n - 1, tl, n - 1, qry[i].z);
    }

    sort(qry, qry + q, [](auto &q1, auto &q2) {
        return q1.i < q2.i;
    });

    for (int i = 0; i < q; i++)
        cout << qry[i].ans << "\n";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int test = 1;
    // cin >> test;
    while (test--)
        solveTestCase();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 41852 KB Output is correct
2 Correct 37 ms 41856 KB Output is correct
3 Correct 37 ms 41848 KB Output is correct
4 Correct 37 ms 41848 KB Output is correct
5 Correct 41 ms 41856 KB Output is correct
6 Correct 37 ms 41848 KB Output is correct
7 Correct 53 ms 44408 KB Output is correct
8 Correct 54 ms 44280 KB Output is correct
9 Correct 54 ms 44280 KB Output is correct
10 Correct 53 ms 44408 KB Output is correct
11 Correct 55 ms 44664 KB Output is correct
12 Correct 50 ms 44288 KB Output is correct
13 Correct 53 ms 44536 KB Output is correct
14 Correct 53 ms 44536 KB Output is correct
15 Correct 54 ms 44444 KB Output is correct
16 Correct 50 ms 44408 KB Output is correct
17 Correct 49 ms 44408 KB Output is correct
18 Correct 52 ms 44408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1951 ms 156664 KB Output is correct
2 Correct 1964 ms 158932 KB Output is correct
3 Correct 1987 ms 158868 KB Output is correct
4 Correct 1203 ms 158072 KB Output is correct
5 Correct 1054 ms 158200 KB Output is correct
6 Correct 765 ms 157480 KB Output is correct
7 Correct 1996 ms 158888 KB Output is correct
8 Correct 1896 ms 158908 KB Output is correct
9 Correct 1858 ms 158840 KB Output is correct
10 Correct 943 ms 158016 KB Output is correct
11 Correct 732 ms 157988 KB Output is correct
12 Correct 718 ms 157092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1951 ms 156664 KB Output is correct
2 Correct 1964 ms 158932 KB Output is correct
3 Correct 1987 ms 158868 KB Output is correct
4 Correct 1203 ms 158072 KB Output is correct
5 Correct 1054 ms 158200 KB Output is correct
6 Correct 765 ms 157480 KB Output is correct
7 Correct 1996 ms 158888 KB Output is correct
8 Correct 1896 ms 158908 KB Output is correct
9 Correct 1858 ms 158840 KB Output is correct
10 Correct 943 ms 158016 KB Output is correct
11 Correct 732 ms 157988 KB Output is correct
12 Correct 718 ms 157092 KB Output is correct
13 Correct 2126 ms 159304 KB Output is correct
14 Correct 2037 ms 159592 KB Output is correct
15 Correct 1969 ms 159044 KB Output is correct
16 Correct 1281 ms 158576 KB Output is correct
17 Correct 1102 ms 158456 KB Output is correct
18 Correct 778 ms 157432 KB Output is correct
19 Correct 2145 ms 159480 KB Output is correct
20 Correct 2106 ms 159224 KB Output is correct
21 Correct 2233 ms 159480 KB Output is correct
22 Correct 929 ms 157816 KB Output is correct
23 Correct 735 ms 157816 KB Output is correct
24 Correct 719 ms 157048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 41852 KB Output is correct
2 Correct 37 ms 41856 KB Output is correct
3 Correct 37 ms 41848 KB Output is correct
4 Correct 37 ms 41848 KB Output is correct
5 Correct 41 ms 41856 KB Output is correct
6 Correct 37 ms 41848 KB Output is correct
7 Correct 53 ms 44408 KB Output is correct
8 Correct 54 ms 44280 KB Output is correct
9 Correct 54 ms 44280 KB Output is correct
10 Correct 53 ms 44408 KB Output is correct
11 Correct 55 ms 44664 KB Output is correct
12 Correct 50 ms 44288 KB Output is correct
13 Correct 53 ms 44536 KB Output is correct
14 Correct 53 ms 44536 KB Output is correct
15 Correct 54 ms 44444 KB Output is correct
16 Correct 50 ms 44408 KB Output is correct
17 Correct 49 ms 44408 KB Output is correct
18 Correct 52 ms 44408 KB Output is correct
19 Correct 1951 ms 156664 KB Output is correct
20 Correct 1964 ms 158932 KB Output is correct
21 Correct 1987 ms 158868 KB Output is correct
22 Correct 1203 ms 158072 KB Output is correct
23 Correct 1054 ms 158200 KB Output is correct
24 Correct 765 ms 157480 KB Output is correct
25 Correct 1996 ms 158888 KB Output is correct
26 Correct 1896 ms 158908 KB Output is correct
27 Correct 1858 ms 158840 KB Output is correct
28 Correct 943 ms 158016 KB Output is correct
29 Correct 732 ms 157988 KB Output is correct
30 Correct 718 ms 157092 KB Output is correct
31 Correct 2126 ms 159304 KB Output is correct
32 Correct 2037 ms 159592 KB Output is correct
33 Correct 1969 ms 159044 KB Output is correct
34 Correct 1281 ms 158576 KB Output is correct
35 Correct 1102 ms 158456 KB Output is correct
36 Correct 778 ms 157432 KB Output is correct
37 Correct 2145 ms 159480 KB Output is correct
38 Correct 2106 ms 159224 KB Output is correct
39 Correct 2233 ms 159480 KB Output is correct
40 Correct 929 ms 157816 KB Output is correct
41 Correct 735 ms 157816 KB Output is correct
42 Correct 719 ms 157048 KB Output is correct
43 Correct 2132 ms 161400 KB Output is correct
44 Correct 2149 ms 161372 KB Output is correct
45 Correct 2045 ms 161440 KB Output is correct
46 Correct 1292 ms 159864 KB Output is correct
47 Correct 1109 ms 159608 KB Output is correct
48 Correct 864 ms 157176 KB Output is correct
49 Correct 2204 ms 161016 KB Output is correct
50 Correct 2096 ms 161208 KB Output is correct
51 Correct 2227 ms 161240 KB Output is correct
52 Correct 975 ms 159496 KB Output is correct
53 Correct 761 ms 158840 KB Output is correct