Submission #1083936

# Submission time Handle Problem Language Result Execution time Memory
1083936 2024-09-04T15:00:41 Z Icelast Exhibition (JOI19_ho_t2) C++17
100 / 100
128 ms 22612 KB
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 4e18+9;
struct SegmentTree{
    struct Node{
        ll mx = 0;
    };
    vector<Node> T;
    int n, N;
    SegmentTree(int n) : n(n){
        N = 1;
        while(N < n) N*=2;
        T.resize(N*2+1);
    };
    void upd(int i, ll x){
        auto upd = [&](auto upd, int node, int low, int high, int i, ll x) -> void{
            if(low == high){
                T[node].mx = max(T[node].mx, x);
                return;
            }
            int mid = (low+high)/2;
            if(i <= mid){
                upd(upd, node*2, low, mid, i, x);
            }else{
                upd(upd, node*2+1, mid+1, high, i, x);
            }
            T[node].mx = max(T[node*2].mx, T[node*2+1].mx);
        };
        upd(upd, 1, 1, N, i, x);
    }
    ll get_max(int l, int r){
        auto get_max = [&](auto get_max, int node, int low, int high, int l, int r) -> ll{
            if(low > r || l > high) return 0;
            if(low >= l && r >= high) return T[node].mx;
            int mid = (low+high)/2;
            return max(get_max(get_max, node*2, low, mid, l, r), get_max(get_max, node*2+1, mid+1, high, l, r));
        };
        return get_max(get_max, 1, 1, N, l, r);
    }
};
struct normalize{
    vector<ll> poi, pot;
    void add(ll x){
        poi.push_back(x);
    }
    void start(){
        sort(poi.begin(), poi.end());
        pot.push_back(poi[0]);
        for(int i = 1; i < (int)poi.size(); i++){
            if(poi[i] != poi[i-1]){
                pot.push_back(poi[i]);
            }
        }
    }
    int encode(ll x){
        return lower_bound(pot.begin(), pot.end(), x) - pot.begin()+1;
    }
};
struct point{
    ll x, y;
};
bool cmpyr(point a, point b){
    return a.y > b.y || (a.y == b.y && a.x > b.x);
}

void solve(){
    int n, m;
    cin >> n >> m;
    vector<point> a(n+1);
    vector<ll> b(m+1);
    for(int i = 1; i <= n; i++){
        cin >> a[i].x >> a[i].y;
    }
    for(int i = 1; i <= m; i++){
        cin >> b[i];
    }
    normalize norm;
    for(int i = 1; i <= n; i++){
        norm.add(a[i].x);
        norm.add(a[i].y);
    }
    for(int i = 1; i <= m; i++){
        norm.add(b[i]);
    }
    norm.start();

    for(int i = 1; i <= n; i++){
        a[i].x = norm.encode(a[i].x);
        a[i].y = norm.encode(a[i].y);
    }
    for(int i = 1; i <= m; i++){
        b[i] = norm.encode(b[i]);
    }
    sort(b.begin()+1, b.end());
    sort(a.begin()+1, a.end(), cmpyr);
    vector<ll> dp(n+1, 0);
    int N = n*2+m+100;
    SegmentTree T(N+1);
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ll mx = T.get_max(1, N)+1;
        ll j = lower_bound(b.begin()+1, b.end(), a[i].x) - b.begin();
        j = m-j+1;
        mx = min(mx, j);
        dp[i] = mx;
        T.upd(a[i].y, dp[i]);
        ans = max(ans, dp[i]);
    }
    cout << ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 852 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 852 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 114 ms 21444 KB Output is correct
39 Correct 83 ms 18628 KB Output is correct
40 Correct 69 ms 18368 KB Output is correct
41 Correct 107 ms 19032 KB Output is correct
42 Correct 110 ms 19264 KB Output is correct
43 Correct 111 ms 20280 KB Output is correct
44 Correct 117 ms 19688 KB Output is correct
45 Correct 126 ms 22080 KB Output is correct
46 Correct 88 ms 19256 KB Output is correct
47 Correct 115 ms 19772 KB Output is correct
48 Correct 93 ms 18700 KB Output is correct
49 Correct 98 ms 12880 KB Output is correct
50 Correct 83 ms 11976 KB Output is correct
51 Correct 113 ms 19924 KB Output is correct
52 Correct 112 ms 21052 KB Output is correct
53 Correct 109 ms 19260 KB Output is correct
54 Correct 71 ms 18120 KB Output is correct
55 Correct 95 ms 19648 KB Output is correct
56 Correct 79 ms 11824 KB Output is correct
57 Correct 33 ms 5716 KB Output is correct
58 Correct 51 ms 10184 KB Output is correct
59 Correct 87 ms 11852 KB Output is correct
60 Correct 32 ms 5960 KB Output is correct
61 Correct 64 ms 10088 KB Output is correct
62 Correct 122 ms 19260 KB Output is correct
63 Correct 127 ms 22612 KB Output is correct
64 Correct 128 ms 22496 KB Output is correct
65 Correct 125 ms 21056 KB Output is correct
66 Correct 125 ms 19260 KB Output is correct
67 Correct 126 ms 20540 KB Output is correct
68 Correct 128 ms 19540 KB Output is correct
69 Correct 120 ms 17960 KB Output is correct
70 Correct 127 ms 21188 KB Output is correct
71 Correct 113 ms 19400 KB Output is correct
72 Correct 92 ms 17928 KB Output is correct
73 Correct 83 ms 18372 KB Output is correct