Submission #1094145

# Submission time Handle Problem Language Result Execution time Memory
1094145 2024-09-28T16:38:06 Z Gray Examination (JOI19_examination) C++17
100 / 100
1279 ms 161260 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define ld long double
#define ff first
#define ss second
#define ln "\n"
#define ord_set tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
const ll MOD = 1e9+7;
const ll INF = 2e18;

struct msegt{
    struct node{
        ord_set items;
    };
    vector<node> t;
    ll sz, rsz;
    msegt(ll N){
        rsz=N;
        sz=N*4;
        t.resize(sz);
    }
    void merge(node &par, node &l, node &r){
        for (auto ch:l.items) par.items.insert(ch);
        for (auto ch:r.items) par.items.insert(ch); 
    }
    void query(ll tl, ll tr, ll v, ll l, ll r, ll x, ll &sum){
        if (tl==l and tr==r){
            // cout << tl << "-" << tr << " * " << x << ": " << t[v].items.size()-t[v].items.order_of_key(x) << ln;
            sum+=t[v].items.size()-t[v].items.order_of_key(x);
        }else if (l>r) return;
        else{
            ll tm = (tl+tr)/2;
            query(tl, tm, v*2, l, min(r, tm), x, sum);
            query(tm+1, tr, v*2+1, max(l, tm+1), tr, x, sum);
        }
    }
    void insert_item(ll tl, ll tr, ll v, ll i, ll x){
        t[v].items.insert(x);
        if (tl==tr){
            return;
        }else{
            ll tm = (tl+tr)/2;
            if (i<=tm){
                insert_item(tl, tm, v*2, i, x);
            }else{
                insert_item(tm+1, tr, v*2+1, i, x);
            }
        }
    }
    ll query(ll l, ll r, ll x){
        ll sum=0;
        query(0, rsz-1, 1, l, r, x, sum);
        return sum;
    }
    void add(ll i, ll x){
        insert_item(0, rsz-1, 1, i, x);
    }
};

void solve(){
    ll n, q; cin >> n >> q;
    vector<pair<ll, ll>> scores(n);
    vector<ll> sums(n);
    for (ll i=0; i<n; i++){
        cin >> scores[i].ff >> scores[i].ss;
        sums[i] = i;
    }
    vector<pair<pair<ll, ll>, pair<ll, ll>>> qs(q);
    for (ll i=0; i<q; i++){
        cin >> qs[i].ff.ff >> qs[i].ff.ss >> qs[i].ss.ff;
        qs[i].ss.ss=i;
    }
    sort(scores.begin(), scores.end());
    // for (auto ch:scores){
    //     cout << ch.ff << "-" << ch.ss << ' ';
    // }
    // cout << ln;
    sort(sums.rbegin(), sums.rend(), [&](ll op1, ll op2){
        return scores[op1].ff+scores[op1].ss<scores[op2].ff+scores[op2].ss;
    });
    // return;
    vector<ll> ys(n);
    for (ll i=0; i<n; i++) ys[i]=scores[i].ss;
    // return;
    msegt tr(n);
    sort(qs.rbegin(), qs.rend(), [](auto op1, auto op2){
        return op1.ss.ff<op2.ss.ff;
    });
    vector<ll> res(q);
    ll l=0;
    // return;
    for (ll i=0; i<q; i++){
        while (l<n and qs[i].ss.ff<=scores[sums[l]].ff+scores[sums[l]].ss){
            tr.add(sums[l], scores[sums[l]].ss);
            l++;
        }
        // cout << qs[i].ss.ss << ": " << l << " -> ";
        pair<ll, ll> seek = {qs[i].ff.ff, 0};
        ll ind = lower_bound(scores.begin(), scores.end(), seek)-scores.begin();
        // cout << ind << ln;
        res[qs[i].ss.ss] = tr.query(ind, n-1, qs[i].ff.ss);
    }
    for (ll i=0; i<q; i++) cout << res[i] << ln;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t=1;
    // cin >> t;
    while (t--) solve();
}
# 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 1 ms 348 KB Output is correct
7 Correct 11 ms 4188 KB Output is correct
8 Correct 12 ms 4268 KB Output is correct
9 Correct 12 ms 4188 KB Output is correct
10 Correct 10 ms 4188 KB Output is correct
11 Correct 10 ms 4188 KB Output is correct
12 Correct 9 ms 4188 KB Output is correct
13 Correct 12 ms 4308 KB Output is correct
14 Correct 10 ms 4188 KB Output is correct
15 Correct 12 ms 4188 KB Output is correct
16 Correct 7 ms 4188 KB Output is correct
17 Correct 9 ms 4188 KB Output is correct
18 Correct 6 ms 4192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1268 ms 158800 KB Output is correct
2 Correct 1243 ms 158800 KB Output is correct
3 Correct 1256 ms 158804 KB Output is correct
4 Correct 758 ms 158288 KB Output is correct
5 Correct 626 ms 158144 KB Output is correct
6 Correct 507 ms 157268 KB Output is correct
7 Correct 1048 ms 158800 KB Output is correct
8 Correct 1112 ms 158644 KB Output is correct
9 Correct 993 ms 158676 KB Output is correct
10 Correct 448 ms 157780 KB Output is correct
11 Correct 572 ms 157776 KB Output is correct
12 Correct 400 ms 156916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1268 ms 158800 KB Output is correct
2 Correct 1243 ms 158800 KB Output is correct
3 Correct 1256 ms 158804 KB Output is correct
4 Correct 758 ms 158288 KB Output is correct
5 Correct 626 ms 158144 KB Output is correct
6 Correct 507 ms 157268 KB Output is correct
7 Correct 1048 ms 158800 KB Output is correct
8 Correct 1112 ms 158644 KB Output is correct
9 Correct 993 ms 158676 KB Output is correct
10 Correct 448 ms 157780 KB Output is correct
11 Correct 572 ms 157776 KB Output is correct
12 Correct 400 ms 156916 KB Output is correct
13 Correct 1115 ms 159224 KB Output is correct
14 Correct 1257 ms 159060 KB Output is correct
15 Correct 1252 ms 158892 KB Output is correct
16 Correct 750 ms 158544 KB Output is correct
17 Correct 633 ms 158548 KB Output is correct
18 Correct 511 ms 157416 KB Output is correct
19 Correct 1106 ms 159312 KB Output is correct
20 Correct 1148 ms 159312 KB Output is correct
21 Correct 946 ms 159276 KB Output is correct
22 Correct 407 ms 157780 KB Output is correct
23 Correct 542 ms 157780 KB Output is correct
24 Correct 388 ms 157008 KB Output is correct
# 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 1 ms 348 KB Output is correct
7 Correct 11 ms 4188 KB Output is correct
8 Correct 12 ms 4268 KB Output is correct
9 Correct 12 ms 4188 KB Output is correct
10 Correct 10 ms 4188 KB Output is correct
11 Correct 10 ms 4188 KB Output is correct
12 Correct 9 ms 4188 KB Output is correct
13 Correct 12 ms 4308 KB Output is correct
14 Correct 10 ms 4188 KB Output is correct
15 Correct 12 ms 4188 KB Output is correct
16 Correct 7 ms 4188 KB Output is correct
17 Correct 9 ms 4188 KB Output is correct
18 Correct 6 ms 4192 KB Output is correct
19 Correct 1268 ms 158800 KB Output is correct
20 Correct 1243 ms 158800 KB Output is correct
21 Correct 1256 ms 158804 KB Output is correct
22 Correct 758 ms 158288 KB Output is correct
23 Correct 626 ms 158144 KB Output is correct
24 Correct 507 ms 157268 KB Output is correct
25 Correct 1048 ms 158800 KB Output is correct
26 Correct 1112 ms 158644 KB Output is correct
27 Correct 993 ms 158676 KB Output is correct
28 Correct 448 ms 157780 KB Output is correct
29 Correct 572 ms 157776 KB Output is correct
30 Correct 400 ms 156916 KB Output is correct
31 Correct 1115 ms 159224 KB Output is correct
32 Correct 1257 ms 159060 KB Output is correct
33 Correct 1252 ms 158892 KB Output is correct
34 Correct 750 ms 158544 KB Output is correct
35 Correct 633 ms 158548 KB Output is correct
36 Correct 511 ms 157416 KB Output is correct
37 Correct 1106 ms 159312 KB Output is correct
38 Correct 1148 ms 159312 KB Output is correct
39 Correct 946 ms 159276 KB Output is correct
40 Correct 407 ms 157780 KB Output is correct
41 Correct 542 ms 157780 KB Output is correct
42 Correct 388 ms 157008 KB Output is correct
43 Correct 1148 ms 161248 KB Output is correct
44 Correct 1120 ms 161260 KB Output is correct
45 Correct 1279 ms 161104 KB Output is correct
46 Correct 797 ms 159572 KB Output is correct
47 Correct 649 ms 159564 KB Output is correct
48 Correct 489 ms 157280 KB Output is correct
49 Correct 1088 ms 161112 KB Output is correct
50 Correct 1012 ms 161104 KB Output is correct
51 Correct 974 ms 161108 KB Output is correct
52 Correct 440 ms 159412 KB Output is correct
53 Correct 580 ms 158804 KB Output is correct