Submission #991555

# Submission time Handle Problem Language Result Execution time Memory
991555 2024-06-02T12:16:56 Z vladilius Examination (JOI19_examination) C++17
0 / 100
418 ms 21184 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<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 344 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 12 ms 976 KB Output is correct
8 Correct 9 ms 980 KB Output is correct
9 Correct 11 ms 984 KB Output is correct
10 Correct 8 ms 984 KB Output is correct
11 Correct 8 ms 984 KB Output is correct
12 Incorrect 6 ms 984 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 418 ms 21184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 418 ms 21184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 12 ms 976 KB Output is correct
8 Correct 9 ms 980 KB Output is correct
9 Correct 11 ms 984 KB Output is correct
10 Correct 8 ms 984 KB Output is correct
11 Correct 8 ms 984 KB Output is correct
12 Incorrect 6 ms 984 KB Output isn't correct
13 Halted 0 ms 0 KB -