Submission #907219

# Submission time Handle Problem Language Result Execution time Memory
907219 2024-01-15T09:19:16 Z a_l_i_r_e_z_a Examination (JOI19_examination) C++17
100 / 100
872 ms 15696 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 = 1200, 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;
        for(; j < n && j % sq; j++){
            if(a[j].F >= A && a[j].S >= B && a[j].F + a[j].S >= Z) ans[ind]++;
        }
        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 8836 KB Output is correct
2 Correct 2 ms 8832 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 3 ms 8792 KB Output is correct
6 Correct 3 ms 8832 KB Output is correct
7 Correct 15 ms 8792 KB Output is correct
8 Correct 12 ms 9028 KB Output is correct
9 Correct 13 ms 9032 KB Output is correct
10 Correct 12 ms 8796 KB Output is correct
11 Correct 12 ms 8792 KB Output is correct
12 Correct 10 ms 8924 KB Output is correct
13 Correct 12 ms 8796 KB Output is correct
14 Correct 13 ms 9004 KB Output is correct
15 Correct 12 ms 8796 KB Output is correct
16 Correct 4 ms 8920 KB Output is correct
17 Correct 11 ms 8844 KB Output is correct
18 Correct 4 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 677 ms 13284 KB Output is correct
2 Correct 690 ms 13292 KB Output is correct
3 Correct 652 ms 13292 KB Output is correct
4 Correct 509 ms 12564 KB Output is correct
5 Correct 436 ms 12624 KB Output is correct
6 Correct 387 ms 11856 KB Output is correct
7 Correct 870 ms 13188 KB Output is correct
8 Correct 548 ms 13208 KB Output is correct
9 Correct 660 ms 13096 KB Output is correct
10 Correct 100 ms 12276 KB Output is correct
11 Correct 405 ms 12276 KB Output is correct
12 Correct 62 ms 11344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 677 ms 13284 KB Output is correct
2 Correct 690 ms 13292 KB Output is correct
3 Correct 652 ms 13292 KB Output is correct
4 Correct 509 ms 12564 KB Output is correct
5 Correct 436 ms 12624 KB Output is correct
6 Correct 387 ms 11856 KB Output is correct
7 Correct 870 ms 13188 KB Output is correct
8 Correct 548 ms 13208 KB Output is correct
9 Correct 660 ms 13096 KB Output is correct
10 Correct 100 ms 12276 KB Output is correct
11 Correct 405 ms 12276 KB Output is correct
12 Correct 62 ms 11344 KB Output is correct
13 Correct 592 ms 13944 KB Output is correct
14 Correct 670 ms 13908 KB Output is correct
15 Correct 655 ms 13392 KB Output is correct
16 Correct 484 ms 12936 KB Output is correct
17 Correct 412 ms 12932 KB Output is correct
18 Correct 347 ms 11824 KB Output is correct
19 Correct 589 ms 13724 KB Output is correct
20 Correct 640 ms 13908 KB Output is correct
21 Correct 604 ms 13704 KB Output is correct
22 Correct 100 ms 12368 KB Output is correct
23 Correct 411 ms 12272 KB Output is correct
24 Correct 62 ms 11344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8836 KB Output is correct
2 Correct 2 ms 8832 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 3 ms 8792 KB Output is correct
6 Correct 3 ms 8832 KB Output is correct
7 Correct 15 ms 8792 KB Output is correct
8 Correct 12 ms 9028 KB Output is correct
9 Correct 13 ms 9032 KB Output is correct
10 Correct 12 ms 8796 KB Output is correct
11 Correct 12 ms 8792 KB Output is correct
12 Correct 10 ms 8924 KB Output is correct
13 Correct 12 ms 8796 KB Output is correct
14 Correct 13 ms 9004 KB Output is correct
15 Correct 12 ms 8796 KB Output is correct
16 Correct 4 ms 8920 KB Output is correct
17 Correct 11 ms 8844 KB Output is correct
18 Correct 4 ms 8796 KB Output is correct
19 Correct 677 ms 13284 KB Output is correct
20 Correct 690 ms 13292 KB Output is correct
21 Correct 652 ms 13292 KB Output is correct
22 Correct 509 ms 12564 KB Output is correct
23 Correct 436 ms 12624 KB Output is correct
24 Correct 387 ms 11856 KB Output is correct
25 Correct 870 ms 13188 KB Output is correct
26 Correct 548 ms 13208 KB Output is correct
27 Correct 660 ms 13096 KB Output is correct
28 Correct 100 ms 12276 KB Output is correct
29 Correct 405 ms 12276 KB Output is correct
30 Correct 62 ms 11344 KB Output is correct
31 Correct 592 ms 13944 KB Output is correct
32 Correct 670 ms 13908 KB Output is correct
33 Correct 655 ms 13392 KB Output is correct
34 Correct 484 ms 12936 KB Output is correct
35 Correct 412 ms 12932 KB Output is correct
36 Correct 347 ms 11824 KB Output is correct
37 Correct 589 ms 13724 KB Output is correct
38 Correct 640 ms 13908 KB Output is correct
39 Correct 604 ms 13704 KB Output is correct
40 Correct 100 ms 12368 KB Output is correct
41 Correct 411 ms 12272 KB Output is correct
42 Correct 62 ms 11344 KB Output is correct
43 Correct 594 ms 15676 KB Output is correct
44 Correct 599 ms 15688 KB Output is correct
45 Correct 679 ms 15624 KB Output is correct
46 Correct 489 ms 13908 KB Output is correct
47 Correct 404 ms 14104 KB Output is correct
48 Correct 339 ms 11660 KB Output is correct
49 Correct 872 ms 15520 KB Output is correct
50 Correct 494 ms 15696 KB Output is correct
51 Correct 615 ms 15444 KB Output is correct
52 Correct 107 ms 13836 KB Output is correct
53 Correct 413 ms 13140 KB Output is correct