Submission #906629

# Submission time Handle Problem Language Result Execution time Memory
906629 2024-01-14T15:16:17 Z a_l_i_r_e_z_a Examination (JOI19_examination) C++17
100 / 100
1198 ms 10864 KB
// In the name of God

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef pair<ll, ll> pll;

#define pb push_back
#define S second
#define F first
#define mp make_pair
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define all(x) (x).begin(), (x).end()
#define len(x) ((ll)(x).size())

const ll maxn = 1e5 + 5;
const ll inf = 1e9 + 7;
ll n, q, cur, sq = 1500, arr[maxn], ans[maxn];
pll a[maxn];
pair<pll, pll> b[maxn];
vector<ll> vec[maxn];

bool cmp(int i, int j){
    return a[i].F + a[i].S < a[j].F + a[j].S;
}

void del(int i){
    ll x = a[i].S;
    i = i / sq;
    vec[i].erase(find(all(vec[i]), x));
}

ll get(ll i, ll x){
    ll res = 0;
    for(; i < n; i += sq){
        int d = lower_bound(all(vec[i / sq]), x) - vec[i / sq].begin();
        res += vec[i / sq].size() - d;
    }
    return res;
}

int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> q;
    for(int i = 0; i < n; i++){
        cin >> a[i].F;
        cin >> a[i].S;
    }
    sort(a, a + n);
    for(int i = 0; i < n; i++){
        vec[i / sq].pb(a[i].S);
    }
    for(int i = 0; i < sq; i++) sort(all(vec[i]));
    for(int i = 0; i < q; i++){
        cin >> b[i].S.F >> b[i].S.S >> b[i].F.F;
        b[i].F.S = i;
    }
    sort(b, b + q);
    for(int i = 0; i < n; i++) arr[i] = i;
    sort(arr, arr + n, cmp);
    for(int i = 0; i < q; i++){
        ll Z = b[i].F.F, ind = b[i].F.S, A = b[i].S.F, B = b[i].S.S;
        while(cur < n && a[arr[cur]].F + a[arr[cur]].S < Z) del(arr[cur++]);
        int j = lower_bound(a, a + n, mp(A, 0ll)) - a;
        j = (j / sq) * sq;
        for(int k = j; ((1ll * k) < n) && ((1ll * k / sq) == (1ll * j / sq)); k++){
            if(a[k].F >= A && a[k].S >= B && a[k].F + a[k].S >= Z) ans[ind]++;
        }
        j += sq;
        if(j < n) ans[ind] += get(j, B);
    }
    for(int i = 0; i < q; i++) cout << ans[i] << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 25 ms 8796 KB Output is correct
8 Correct 25 ms 8864 KB Output is correct
9 Correct 25 ms 8796 KB Output is correct
10 Correct 26 ms 8844 KB Output is correct
11 Correct 24 ms 8796 KB Output is correct
12 Correct 23 ms 8792 KB Output is correct
13 Correct 24 ms 8796 KB Output is correct
14 Correct 24 ms 8796 KB Output is correct
15 Correct 24 ms 8796 KB Output is correct
16 Correct 14 ms 8796 KB Output is correct
17 Correct 23 ms 8796 KB Output is correct
18 Correct 8 ms 8888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1069 ms 10864 KB Output is correct
2 Correct 1061 ms 10640 KB Output is correct
3 Correct 1055 ms 10636 KB Output is correct
4 Correct 932 ms 10836 KB Output is correct
5 Correct 902 ms 10636 KB Output is correct
6 Correct 830 ms 10668 KB Output is correct
7 Correct 1175 ms 10664 KB Output is correct
8 Correct 961 ms 10836 KB Output is correct
9 Correct 1020 ms 10836 KB Output is correct
10 Correct 674 ms 10376 KB Output is correct
11 Correct 840 ms 10580 KB Output is correct
12 Correct 608 ms 10324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1069 ms 10864 KB Output is correct
2 Correct 1061 ms 10640 KB Output is correct
3 Correct 1055 ms 10636 KB Output is correct
4 Correct 932 ms 10836 KB Output is correct
5 Correct 902 ms 10636 KB Output is correct
6 Correct 830 ms 10668 KB Output is correct
7 Correct 1175 ms 10664 KB Output is correct
8 Correct 961 ms 10836 KB Output is correct
9 Correct 1020 ms 10836 KB Output is correct
10 Correct 674 ms 10376 KB Output is correct
11 Correct 840 ms 10580 KB Output is correct
12 Correct 608 ms 10324 KB Output is correct
13 Correct 1012 ms 10636 KB Output is correct
14 Correct 1091 ms 10632 KB Output is correct
15 Correct 1066 ms 10668 KB Output is correct
16 Correct 934 ms 10632 KB Output is correct
17 Correct 880 ms 10632 KB Output is correct
18 Correct 836 ms 10632 KB Output is correct
19 Correct 1014 ms 10832 KB Output is correct
20 Correct 1057 ms 10628 KB Output is correct
21 Correct 997 ms 10632 KB Output is correct
22 Correct 674 ms 10380 KB Output is correct
23 Correct 858 ms 10372 KB Output is correct
24 Correct 605 ms 10116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 25 ms 8796 KB Output is correct
8 Correct 25 ms 8864 KB Output is correct
9 Correct 25 ms 8796 KB Output is correct
10 Correct 26 ms 8844 KB Output is correct
11 Correct 24 ms 8796 KB Output is correct
12 Correct 23 ms 8792 KB Output is correct
13 Correct 24 ms 8796 KB Output is correct
14 Correct 24 ms 8796 KB Output is correct
15 Correct 24 ms 8796 KB Output is correct
16 Correct 14 ms 8796 KB Output is correct
17 Correct 23 ms 8796 KB Output is correct
18 Correct 8 ms 8888 KB Output is correct
19 Correct 1069 ms 10864 KB Output is correct
20 Correct 1061 ms 10640 KB Output is correct
21 Correct 1055 ms 10636 KB Output is correct
22 Correct 932 ms 10836 KB Output is correct
23 Correct 902 ms 10636 KB Output is correct
24 Correct 830 ms 10668 KB Output is correct
25 Correct 1175 ms 10664 KB Output is correct
26 Correct 961 ms 10836 KB Output is correct
27 Correct 1020 ms 10836 KB Output is correct
28 Correct 674 ms 10376 KB Output is correct
29 Correct 840 ms 10580 KB Output is correct
30 Correct 608 ms 10324 KB Output is correct
31 Correct 1012 ms 10636 KB Output is correct
32 Correct 1091 ms 10632 KB Output is correct
33 Correct 1066 ms 10668 KB Output is correct
34 Correct 934 ms 10632 KB Output is correct
35 Correct 880 ms 10632 KB Output is correct
36 Correct 836 ms 10632 KB Output is correct
37 Correct 1014 ms 10832 KB Output is correct
38 Correct 1057 ms 10628 KB Output is correct
39 Correct 997 ms 10632 KB Output is correct
40 Correct 674 ms 10380 KB Output is correct
41 Correct 858 ms 10372 KB Output is correct
42 Correct 605 ms 10116 KB Output is correct
43 Correct 1016 ms 10640 KB Output is correct
44 Correct 1018 ms 10632 KB Output is correct
45 Correct 1081 ms 10644 KB Output is correct
46 Correct 933 ms 10640 KB Output is correct
47 Correct 883 ms 10632 KB Output is correct
48 Correct 820 ms 10416 KB Output is correct
49 Correct 1198 ms 10636 KB Output is correct
50 Correct 920 ms 10840 KB Output is correct
51 Correct 973 ms 10632 KB Output is correct
52 Correct 682 ms 10376 KB Output is correct
53 Correct 859 ms 10376 KB Output is correct