Submission #752334

# Submission time Handle Problem Language Result Execution time Memory
752334 2023-06-02T21:43:36 Z BidoTeima Examination (JOI19_examination) C++17
100 / 100
536 ms 52492 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 3;
vector<int> st[2][4 * N];
int a[2][N];
void build(bool b, int l, int r, int node){
    if(l == r){
        st[b][node] = {a[b][l]};
        return;
    }
    int mid = (l + r) >> 1;
    build(b, l, mid, 2 * node + 1);
    build(b, mid + 1, r, 2 * node + 2); 
    for(int x : st[b][2 * node + 1])st[b][node].push_back(x);
    for(int x : st[b][2 * node + 2])st[b][node].push_back(x);
    sort(st[b][node].begin(),st[b][node].end());
    return;
}
int query(bool b, int ql, int qr, int x, int l, int r, int node){
    if(l > r)
        return 0;
    if(ql <= l && r <= qr){
        return st[b][node].end() - lower_bound(st[b][node].begin(), st[b][node].end(), x);
    }
    if(r < ql || l > qr){
        return 0;
    }
    int mid = (l + r) >> 1;
    return query(b, ql, qr, x, l, mid, 2 * node + 1) + 
            query(b, ql, qr, x, mid + 1, r, 2 * node + 2);
}
int main()
{ 
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); 
    int n,q;
    cin>>n>>q;
    pair<int,int>arr[n];
    for(int i = 0; i < n; i++){
        cin>>arr[i].first>>arr[i].second;
    }
    sort(arr,arr+n);
    for(int i = 0; i < n; i++){
        a[0][i] = arr[i].second;
        a[1][i] = arr[i].first + arr[i].second;
    }
    build(0,0,n-1,0);
    build(1,0,n-1,0);
    while(q--){
        int x,y,z;
        cin>>x>>y>>z;
        int l = lower_bound(arr, arr+n, make_pair(x, 0)) - arr;
        if(x + y >= z){
            //[l,n-1]
            cout<<query(0, l, n - 1, y, 0, n - 1, 0)<<'\n';
        } else{
            int r = n;
            int lo = l, hi = n - 1, mid;
            while(lo <= hi){
                mid = (lo + hi) >> 1;
                if(y >= z - arr[mid].first){
                    r = mid;
                    hi = mid - 1;
                } else{
                    lo = mid + 1;
                }
            }
            cout<<query(1, l, r - 1, z, 0, n - 1, 0) + query(0, r, n - 1, y, 0, n - 1, 0)<<'\n';
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19028 KB Output is correct
2 Correct 10 ms 19028 KB Output is correct
3 Correct 10 ms 19016 KB Output is correct
4 Correct 11 ms 19028 KB Output is correct
5 Correct 10 ms 19120 KB Output is correct
6 Correct 10 ms 19072 KB Output is correct
7 Correct 16 ms 19892 KB Output is correct
8 Correct 17 ms 19900 KB Output is correct
9 Correct 17 ms 19924 KB Output is correct
10 Correct 16 ms 19924 KB Output is correct
11 Correct 15 ms 19892 KB Output is correct
12 Correct 16 ms 19796 KB Output is correct
13 Correct 26 ms 19852 KB Output is correct
14 Correct 17 ms 19940 KB Output is correct
15 Correct 18 ms 19924 KB Output is correct
16 Correct 13 ms 19924 KB Output is correct
17 Correct 16 ms 19956 KB Output is correct
18 Correct 13 ms 19764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 348 ms 47524 KB Output is correct
2 Correct 341 ms 47552 KB Output is correct
3 Correct 354 ms 47588 KB Output is correct
4 Correct 263 ms 47684 KB Output is correct
5 Correct 266 ms 47684 KB Output is correct
6 Correct 166 ms 47644 KB Output is correct
7 Correct 380 ms 47596 KB Output is correct
8 Correct 327 ms 47620 KB Output is correct
9 Correct 302 ms 47684 KB Output is correct
10 Correct 157 ms 47372 KB Output is correct
11 Correct 228 ms 47460 KB Output is correct
12 Correct 129 ms 47328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 348 ms 47524 KB Output is correct
2 Correct 341 ms 47552 KB Output is correct
3 Correct 354 ms 47588 KB Output is correct
4 Correct 263 ms 47684 KB Output is correct
5 Correct 266 ms 47684 KB Output is correct
6 Correct 166 ms 47644 KB Output is correct
7 Correct 380 ms 47596 KB Output is correct
8 Correct 327 ms 47620 KB Output is correct
9 Correct 302 ms 47684 KB Output is correct
10 Correct 157 ms 47372 KB Output is correct
11 Correct 228 ms 47460 KB Output is correct
12 Correct 129 ms 47328 KB Output is correct
13 Correct 434 ms 47572 KB Output is correct
14 Correct 396 ms 50452 KB Output is correct
15 Correct 356 ms 50080 KB Output is correct
16 Correct 399 ms 49744 KB Output is correct
17 Correct 243 ms 49660 KB Output is correct
18 Correct 217 ms 48592 KB Output is correct
19 Correct 420 ms 50568 KB Output is correct
20 Correct 443 ms 50588 KB Output is correct
21 Correct 426 ms 50488 KB Output is correct
22 Correct 158 ms 49128 KB Output is correct
23 Correct 214 ms 49208 KB Output is correct
24 Correct 144 ms 48284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19028 KB Output is correct
2 Correct 10 ms 19028 KB Output is correct
3 Correct 10 ms 19016 KB Output is correct
4 Correct 11 ms 19028 KB Output is correct
5 Correct 10 ms 19120 KB Output is correct
6 Correct 10 ms 19072 KB Output is correct
7 Correct 16 ms 19892 KB Output is correct
8 Correct 17 ms 19900 KB Output is correct
9 Correct 17 ms 19924 KB Output is correct
10 Correct 16 ms 19924 KB Output is correct
11 Correct 15 ms 19892 KB Output is correct
12 Correct 16 ms 19796 KB Output is correct
13 Correct 26 ms 19852 KB Output is correct
14 Correct 17 ms 19940 KB Output is correct
15 Correct 18 ms 19924 KB Output is correct
16 Correct 13 ms 19924 KB Output is correct
17 Correct 16 ms 19956 KB Output is correct
18 Correct 13 ms 19764 KB Output is correct
19 Correct 348 ms 47524 KB Output is correct
20 Correct 341 ms 47552 KB Output is correct
21 Correct 354 ms 47588 KB Output is correct
22 Correct 263 ms 47684 KB Output is correct
23 Correct 266 ms 47684 KB Output is correct
24 Correct 166 ms 47644 KB Output is correct
25 Correct 380 ms 47596 KB Output is correct
26 Correct 327 ms 47620 KB Output is correct
27 Correct 302 ms 47684 KB Output is correct
28 Correct 157 ms 47372 KB Output is correct
29 Correct 228 ms 47460 KB Output is correct
30 Correct 129 ms 47328 KB Output is correct
31 Correct 434 ms 47572 KB Output is correct
32 Correct 396 ms 50452 KB Output is correct
33 Correct 356 ms 50080 KB Output is correct
34 Correct 399 ms 49744 KB Output is correct
35 Correct 243 ms 49660 KB Output is correct
36 Correct 217 ms 48592 KB Output is correct
37 Correct 420 ms 50568 KB Output is correct
38 Correct 443 ms 50588 KB Output is correct
39 Correct 426 ms 50488 KB Output is correct
40 Correct 158 ms 49128 KB Output is correct
41 Correct 214 ms 49208 KB Output is correct
42 Correct 144 ms 48284 KB Output is correct
43 Correct 431 ms 52492 KB Output is correct
44 Correct 419 ms 52420 KB Output is correct
45 Correct 460 ms 52472 KB Output is correct
46 Correct 347 ms 50880 KB Output is correct
47 Correct 255 ms 50980 KB Output is correct
48 Correct 177 ms 48524 KB Output is correct
49 Correct 511 ms 52304 KB Output is correct
50 Correct 432 ms 52372 KB Output is correct
51 Correct 536 ms 52300 KB Output is correct
52 Correct 173 ms 50760 KB Output is correct
53 Correct 224 ms 49992 KB Output is correct