Submission #495922

# Submission time Handle Problem Language Result Execution time Memory
495922 2021-12-20T07:54:26 Z Jarif_Rahman Exhibition (JOI19_ho_t2) C++17
100 / 100
108 ms 10608 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
struct segtree{
    struct node{
        int in; ll mx;
        node(){
            mx = 0;
        }
        node(int _in, ll x){
            in = _in;
            mx = x;
        }
        node operator+(node a){
            return (a.mx >= mx ? node(a.in, a.mx):node(in, mx));
        }
    };
    int k;
    vector<node> v;
    segtree(int n){
        k = 1;
        while(k < n) k*=2;
        k*=2;
        v.resize(k);
        for(int i = k-1; i >= k/2; i--) v[i].in = i-k/2;
        for(int i = k/2-1; i > 0; i--) v[i] = v[2*i]+v[2*i+1];
    }
    void upd(int in, ll x){
        in+=k/2;
        v[in].mx = x;
        in/=2;
        while(in > 0){
            v[in] = v[2*in]+v[2*in+1];
            in/=2;
        }
    }
    pair<ll, int> smx(int l, int r, int nd, int a, int b){
        if(a > r || b < l) return {-1, -1};
        if(a >= l && b <= r) return {v[nd].mx, v[nd].in};
        int md = (a+b)/2;
        return max(smx(l, r, 2*nd, a, md), smx(l, r, 2*nd+1, md+1, b));
    }
    pair<ll, int> smx(int l, int r){
        return smx(l, r, 1, 0, k/2-1);
    }
};
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m; cin >> n >> m;
    
    vector<pair<ll, ll>> pics(n);
    vector<ll> frames(m), bs;

    for(auto &p: pics) cin >> p.f >> p.sc, bs.pb(-p.f);
    for(ll &x: frames) cin >> x;

    sort(pics.begin(), pics.end());
    sort(bs.begin(), bs.end());
    sort(frames.begin(), frames.end());

    segtree seg(n);
    for(int i = 0; i < n; i++) seg.upd(i, pics[i].sc);

    int ans = 0;
    for(int i = m-1; i >= 0; i--){
        auto it = lower_bound(bs.begin(), bs.end(), -frames[i]);
        int in = n-1-(it-bs.begin());
        if(in == -1) continue;
        auto p = seg.smx(0, in);
        if(p.f == 0) continue;
        ans++;
        seg.upd(p.sc, 0);
    }

    cout << ans << "\n";

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 380 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2 ms 328 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 324 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 2 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 380 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2 ms 328 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 324 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 2 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 90 ms 10512 KB Output is correct
39 Correct 78 ms 10532 KB Output is correct
40 Correct 76 ms 10604 KB Output is correct
41 Correct 108 ms 10564 KB Output is correct
42 Correct 58 ms 10532 KB Output is correct
43 Correct 67 ms 10584 KB Output is correct
44 Correct 82 ms 10596 KB Output is correct
45 Correct 91 ms 10484 KB Output is correct
46 Correct 93 ms 10548 KB Output is correct
47 Correct 77 ms 10048 KB Output is correct
48 Correct 67 ms 9936 KB Output is correct
49 Correct 70 ms 9284 KB Output is correct
50 Correct 68 ms 9280 KB Output is correct
51 Correct 62 ms 10572 KB Output is correct
52 Correct 67 ms 10540 KB Output is correct
53 Correct 76 ms 10540 KB Output is correct
54 Correct 72 ms 10604 KB Output is correct
55 Correct 87 ms 10596 KB Output is correct
56 Correct 44 ms 8948 KB Output is correct
57 Correct 18 ms 1984 KB Output is correct
58 Correct 47 ms 8824 KB Output is correct
59 Correct 42 ms 8760 KB Output is correct
60 Correct 21 ms 1984 KB Output is correct
61 Correct 46 ms 5708 KB Output is correct
62 Correct 84 ms 10516 KB Output is correct
63 Correct 88 ms 10572 KB Output is correct
64 Correct 87 ms 10608 KB Output is correct
65 Correct 81 ms 10596 KB Output is correct
66 Correct 82 ms 10608 KB Output is correct
67 Correct 81 ms 10484 KB Output is correct
68 Correct 81 ms 10596 KB Output is correct
69 Correct 82 ms 10556 KB Output is correct
70 Correct 85 ms 10504 KB Output is correct
71 Correct 83 ms 10480 KB Output is correct
72 Correct 86 ms 10476 KB Output is correct
73 Correct 75 ms 10556 KB Output is correct