Submission #991556

# Submission time Handle Problem Language Result Execution time Memory
991556 2024-06-02T12:17:29 Z vladilius Examination (JOI19_examination) C++17
100 / 100
536 ms 31188 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;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
#define ins insert
using ordered_set = tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>;
const int inf = 2e9 + 5;
 
struct OS{
    ordered_set st;
    void add(int x){
        st.ins(x);
    }
    int get(int x){
        return st.order_of_key(x);
    }
    void clear(){
        st.clear();
    }
};
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    struct data{
        int x, y, z, i;
    };
    
    auto cmp = [&](data& a, data& b){
        return a.x < b.x;
    };
    
    int n, q; cin>>n>>q;
    vector<pii> t(n + 1);
    for (int i = 1; i <= n; i++){
        cin>>t[i].ff>>t[i].ss;
    }
    sort(t.begin() + 1, t.end());
    
    vector<data> qs(q + 1);
    for (int i = 1; i <= q; i++){
        cin>>qs[i].x>>qs[i].y>>qs[i].z;
        qs[i].i = i;
    }
    sort(qs.begin() + 1, qs.end(), cmp);
    vector<data> all = {{}};
    
    int j = n, cur = 1;
    for (int i = q; i > 0; i--){
        while (j > 0 && t[j].ff >= qs[i].x){
            all.pb({cur++, t[j].ss, t[j].ff + t[j].ss, 0});
            j--;
        }
        all.pb({cur, inf, inf, qs[i].i});
        all.pb({cur, qs[i].y, inf, -qs[i].i});
        all.pb({cur, inf, qs[i].z, -qs[i].i});
        all.pb({cur++, qs[i].y, qs[i].z, qs[i].i});
    }
    sort(all.begin() + 1, all.end(), cmp);
    
    vector<int> out(q + 1), cnt(all.size());
    OS T;
    function<void(int, int)> solve = [&](int l, int r){
        if (l == r) return;
        int m = (l + r) / 2;
        solve(l, m);
        solve(m + 1, r);
        
        vector<data> arr;
        for (int i = l; i <= m; i++){
            if (all[i].i == 0) arr.pb({all[i].y, all[i].z, 0, 0});
        }
        for (int i = m + 1; i <= r; i++){
            if (all[i].i != 0) arr.pb({all[i].y, all[i].z, 0, i});
        }
        sort(arr.begin(), arr.end(), cmp);
        int i = 0, j = 0;
        while (i < arr.size()){
            while (j < arr.size() && arr[j].x < arr[i].x){
                if (arr[j].i == 0) T.add(arr[j].y);
                j++;
            }
            if (arr[i].i) cnt[arr[i].i] += T.get(arr[i].y);
            i++;
        }
        T.clear();
    };
    solve(1, (int) all.size() - 1);
    for (int i = 1; i < all.size(); i++){
        if (all[i].i == 0) continue;
        out[abs(all[i].i)] += (2 * (all[i].i > 0) - 1) * cnt[i];
    }
    for (int i = 1; i <= q; i++){
        cout<<out[i]<<"\n";
    }
}

Compilation message

examination.cpp: In lambda function:
examination.cpp:86:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<main()::data>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |         while (i < arr.size()){
      |                ~~^~~~~~~~~~~~
examination.cpp:87:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<main()::data>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |             while (j < arr.size() && arr[j].x < arr[i].x){
      |                    ~~^~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:97:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<main()::data>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |     for (int i = 1; i < all.size(); i++){
      |                     ~~^~~~~~~~~~~~
# 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 0 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 980 KB Output is correct
8 Correct 10 ms 980 KB Output is correct
9 Correct 9 ms 984 KB Output is correct
10 Correct 12 ms 992 KB Output is correct
11 Correct 11 ms 984 KB Output is correct
12 Correct 9 ms 972 KB Output is correct
13 Correct 11 ms 984 KB Output is correct
14 Correct 9 ms 984 KB Output is correct
15 Correct 9 ms 980 KB Output is correct
16 Correct 7 ms 1040 KB Output is correct
17 Correct 8 ms 984 KB Output is correct
18 Correct 5 ms 900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 425 ms 20832 KB Output is correct
2 Correct 422 ms 23588 KB Output is correct
3 Correct 421 ms 23488 KB Output is correct
4 Correct 434 ms 23888 KB Output is correct
5 Correct 352 ms 23252 KB Output is correct
6 Correct 283 ms 22792 KB Output is correct
7 Correct 480 ms 27940 KB Output is correct
8 Correct 426 ms 23344 KB Output is correct
9 Correct 460 ms 27864 KB Output is correct
10 Correct 401 ms 22640 KB Output is correct
11 Correct 352 ms 22972 KB Output is correct
12 Correct 231 ms 21688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 425 ms 20832 KB Output is correct
2 Correct 422 ms 23588 KB Output is correct
3 Correct 421 ms 23488 KB Output is correct
4 Correct 434 ms 23888 KB Output is correct
5 Correct 352 ms 23252 KB Output is correct
6 Correct 283 ms 22792 KB Output is correct
7 Correct 480 ms 27940 KB Output is correct
8 Correct 426 ms 23344 KB Output is correct
9 Correct 460 ms 27864 KB Output is correct
10 Correct 401 ms 22640 KB Output is correct
11 Correct 352 ms 22972 KB Output is correct
12 Correct 231 ms 21688 KB Output is correct
13 Correct 468 ms 23856 KB Output is correct
14 Correct 469 ms 23996 KB Output is correct
15 Correct 431 ms 23580 KB Output is correct
16 Correct 437 ms 24116 KB Output is correct
17 Correct 400 ms 23220 KB Output is correct
18 Correct 302 ms 23052 KB Output is correct
19 Correct 467 ms 23736 KB Output is correct
20 Correct 494 ms 23996 KB Output is correct
21 Correct 492 ms 30228 KB Output is correct
22 Correct 375 ms 22580 KB Output is correct
23 Correct 400 ms 22972 KB Output is correct
24 Correct 235 ms 21692 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 0 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 980 KB Output is correct
8 Correct 10 ms 980 KB Output is correct
9 Correct 9 ms 984 KB Output is correct
10 Correct 12 ms 992 KB Output is correct
11 Correct 11 ms 984 KB Output is correct
12 Correct 9 ms 972 KB Output is correct
13 Correct 11 ms 984 KB Output is correct
14 Correct 9 ms 984 KB Output is correct
15 Correct 9 ms 980 KB Output is correct
16 Correct 7 ms 1040 KB Output is correct
17 Correct 8 ms 984 KB Output is correct
18 Correct 5 ms 900 KB Output is correct
19 Correct 425 ms 20832 KB Output is correct
20 Correct 422 ms 23588 KB Output is correct
21 Correct 421 ms 23488 KB Output is correct
22 Correct 434 ms 23888 KB Output is correct
23 Correct 352 ms 23252 KB Output is correct
24 Correct 283 ms 22792 KB Output is correct
25 Correct 480 ms 27940 KB Output is correct
26 Correct 426 ms 23344 KB Output is correct
27 Correct 460 ms 27864 KB Output is correct
28 Correct 401 ms 22640 KB Output is correct
29 Correct 352 ms 22972 KB Output is correct
30 Correct 231 ms 21688 KB Output is correct
31 Correct 468 ms 23856 KB Output is correct
32 Correct 469 ms 23996 KB Output is correct
33 Correct 431 ms 23580 KB Output is correct
34 Correct 437 ms 24116 KB Output is correct
35 Correct 400 ms 23220 KB Output is correct
36 Correct 302 ms 23052 KB Output is correct
37 Correct 467 ms 23736 KB Output is correct
38 Correct 494 ms 23996 KB Output is correct
39 Correct 492 ms 30228 KB Output is correct
40 Correct 375 ms 22580 KB Output is correct
41 Correct 400 ms 22972 KB Output is correct
42 Correct 235 ms 21692 KB Output is correct
43 Correct 520 ms 25768 KB Output is correct
44 Correct 513 ms 25784 KB Output is correct
45 Correct 472 ms 26044 KB Output is correct
46 Correct 425 ms 25532 KB Output is correct
47 Correct 430 ms 24340 KB Output is correct
48 Correct 296 ms 22712 KB Output is correct
49 Correct 534 ms 31188 KB Output is correct
50 Correct 444 ms 25640 KB Output is correct
51 Correct 536 ms 30052 KB Output is correct
52 Correct 393 ms 24272 KB Output is correct
53 Correct 369 ms 23480 KB Output is correct