답안 #1027397

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1027397 2024-07-19T05:43:25 Z vjudge1 Examination (JOI19_examination) C++17
100 / 100
1614 ms 173032 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;

typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,
tree_order_statistics_node_update> Tree;

const int N = 100100;
const int M = (1 << 18);

Tree st[2 * M];

void insert(int x, pair<int, int> a) {
    // cout << "added: " << '(' << x << ' ' << a.first << ')' << '\n';
    for (x += M; x; x >>= 1) {
        st[x].insert(a);
    }
}

int get(int x, int y) {
    int ans = 0;
    for (int ql = x + M, qr = 2 * M; ql < qr; ql >>= 1, qr >>= 1) {
        if (ql & 1) {
            ans += (int)st[ql].size() - st[ql].order_of_key({y, 0});
            ql++;
        } 
        if (qr & 1) {
            --qr;
            ans += (int)st[qr].size() - st[qr].order_of_key({y, 0});
        }
    }
    return ans;
}

int n, q;
pair<int, int> p[N];
array<int, 4> t[N];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n >> q;
    int res[q];

    for (int i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
    }
    for (int i = 0; i < q; i++) {
        cin >> t[i][0] >> t[i][1] >> t[i][2];
        t[i][3] = i;
    }

    vector<int> keys;
    for (int i = 0; i < n; i++) keys.push_back(p[i].first);
    for (int i = 0; i < q; i++) keys.push_back(t[i][0]);
    
    sort(keys.begin(), keys.end());
    keys.erase(unique(keys.begin(), keys.end()), keys.end());

    sort(p, p + n, [](pair<int, int> a, pair<int, int> b) {
        return a.first + a.second > b.first + b.second;
    });
    sort(t, t + q, [](array<int, 4> a, array<int, 4> b) {
        return a[2] > b[2];
    });
    
    int l = 0;
    for (int i = 0; i < q; i++) {
        auto cur = t[i];
        int z = cur[2];
        while (l < n && p[l].first + p[l].second >= z) {
            int x = lower_bound(keys.begin(), keys.end(), p[l].first) - keys.begin();
            insert(x, {p[l].second, l});
            l++;
        }
        int x = cur[0], y = cur[1];
        x = lower_bound(keys.begin(), keys.end(), x) - keys.begin();
        // cout << "ask: " << '(' << x << ' ' << y << ')' << '\n';    
        res[cur[3]] = get(x, y);
    }
    
    for (int i = 0; i < q; i++) {
        cout << res[i] << '\n';
    }

}
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 49756 KB Output is correct
2 Correct 26 ms 49744 KB Output is correct
3 Correct 27 ms 49644 KB Output is correct
4 Correct 28 ms 49792 KB Output is correct
5 Correct 27 ms 49752 KB Output is correct
6 Correct 28 ms 49752 KB Output is correct
7 Correct 40 ms 53492 KB Output is correct
8 Correct 52 ms 53332 KB Output is correct
9 Correct 40 ms 53328 KB Output is correct
10 Correct 36 ms 53328 KB Output is correct
11 Correct 41 ms 53332 KB Output is correct
12 Correct 40 ms 53300 KB Output is correct
13 Correct 41 ms 53340 KB Output is correct
14 Correct 43 ms 53308 KB Output is correct
15 Correct 41 ms 53464 KB Output is correct
16 Correct 40 ms 53332 KB Output is correct
17 Correct 40 ms 53476 KB Output is correct
18 Correct 43 ms 53328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1614 ms 172716 KB Output is correct
2 Correct 1472 ms 172752 KB Output is correct
3 Correct 1396 ms 173032 KB Output is correct
4 Correct 931 ms 172748 KB Output is correct
5 Correct 736 ms 172588 KB Output is correct
6 Correct 665 ms 172596 KB Output is correct
7 Correct 1139 ms 172744 KB Output is correct
8 Correct 1201 ms 172740 KB Output is correct
9 Correct 1092 ms 172652 KB Output is correct
10 Correct 591 ms 172472 KB Output is correct
11 Correct 771 ms 172588 KB Output is correct
12 Correct 1051 ms 172268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1614 ms 172716 KB Output is correct
2 Correct 1472 ms 172752 KB Output is correct
3 Correct 1396 ms 173032 KB Output is correct
4 Correct 931 ms 172748 KB Output is correct
5 Correct 736 ms 172588 KB Output is correct
6 Correct 665 ms 172596 KB Output is correct
7 Correct 1139 ms 172744 KB Output is correct
8 Correct 1201 ms 172740 KB Output is correct
9 Correct 1092 ms 172652 KB Output is correct
10 Correct 591 ms 172472 KB Output is correct
11 Correct 771 ms 172588 KB Output is correct
12 Correct 1051 ms 172268 KB Output is correct
13 Correct 1205 ms 172536 KB Output is correct
14 Correct 1403 ms 172744 KB Output is correct
15 Correct 1230 ms 172752 KB Output is correct
16 Correct 823 ms 172736 KB Output is correct
17 Correct 689 ms 172668 KB Output is correct
18 Correct 710 ms 172608 KB Output is correct
19 Correct 1242 ms 172652 KB Output is correct
20 Correct 1191 ms 172572 KB Output is correct
21 Correct 1044 ms 172708 KB Output is correct
22 Correct 716 ms 172496 KB Output is correct
23 Correct 770 ms 172392 KB Output is correct
24 Correct 1126 ms 172300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 49756 KB Output is correct
2 Correct 26 ms 49744 KB Output is correct
3 Correct 27 ms 49644 KB Output is correct
4 Correct 28 ms 49792 KB Output is correct
5 Correct 27 ms 49752 KB Output is correct
6 Correct 28 ms 49752 KB Output is correct
7 Correct 40 ms 53492 KB Output is correct
8 Correct 52 ms 53332 KB Output is correct
9 Correct 40 ms 53328 KB Output is correct
10 Correct 36 ms 53328 KB Output is correct
11 Correct 41 ms 53332 KB Output is correct
12 Correct 40 ms 53300 KB Output is correct
13 Correct 41 ms 53340 KB Output is correct
14 Correct 43 ms 53308 KB Output is correct
15 Correct 41 ms 53464 KB Output is correct
16 Correct 40 ms 53332 KB Output is correct
17 Correct 40 ms 53476 KB Output is correct
18 Correct 43 ms 53328 KB Output is correct
19 Correct 1614 ms 172716 KB Output is correct
20 Correct 1472 ms 172752 KB Output is correct
21 Correct 1396 ms 173032 KB Output is correct
22 Correct 931 ms 172748 KB Output is correct
23 Correct 736 ms 172588 KB Output is correct
24 Correct 665 ms 172596 KB Output is correct
25 Correct 1139 ms 172744 KB Output is correct
26 Correct 1201 ms 172740 KB Output is correct
27 Correct 1092 ms 172652 KB Output is correct
28 Correct 591 ms 172472 KB Output is correct
29 Correct 771 ms 172588 KB Output is correct
30 Correct 1051 ms 172268 KB Output is correct
31 Correct 1205 ms 172536 KB Output is correct
32 Correct 1403 ms 172744 KB Output is correct
33 Correct 1230 ms 172752 KB Output is correct
34 Correct 823 ms 172736 KB Output is correct
35 Correct 689 ms 172668 KB Output is correct
36 Correct 710 ms 172608 KB Output is correct
37 Correct 1242 ms 172652 KB Output is correct
38 Correct 1191 ms 172572 KB Output is correct
39 Correct 1044 ms 172708 KB Output is correct
40 Correct 716 ms 172496 KB Output is correct
41 Correct 770 ms 172392 KB Output is correct
42 Correct 1126 ms 172300 KB Output is correct
43 Correct 1202 ms 172588 KB Output is correct
44 Correct 1286 ms 172728 KB Output is correct
45 Correct 1385 ms 172748 KB Output is correct
46 Correct 812 ms 172556 KB Output is correct
47 Correct 981 ms 172744 KB Output is correct
48 Correct 646 ms 172536 KB Output is correct
49 Correct 1175 ms 172768 KB Output is correct
50 Correct 1153 ms 172716 KB Output is correct
51 Correct 1078 ms 172656 KB Output is correct
52 Correct 1010 ms 172572 KB Output is correct
53 Correct 728 ms 172496 KB Output is correct