제출 #1123389

#제출 시각아이디문제언어결과실행 시간메모리
1123389LucaIlieExhibition (JOI19_ho_t2)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h>

using namespace std;

struct painting {
    int size, value;
};

struct AIB {
    int n;
    vector<int> aib;

    void init( int _n ) {
        n = _n;
        aib.clear();
        aib.resize( n + 1 );
    }

    void update( int i, int x ) {
        while ( i <= n ) {
            aib[i] = max( aib[i], x );
            i += (i & -i);
        }
    }

    int query( int i ) {
        int s = 0;
        while ( i > 0 ) {
            s = max( s, aib[i] );
            i -= (i & -i);
        }
        return s;
    }
};

const int MAX_N = 1e5;
const int MAX_M = 1e5;
painting paintings[MAX_N + 1];
int frames[MAX_M + 1];
int dp[MAX_N + 1];
AIB dps;
map<int, int> normal;

int main() {
    ios_base::sync_with_stdio( false );
    cin.tie( nullptr );

    int n, m;

    cin >> n >> m;
    for ( int i = 1; i <= n; i++ ) {
        cin >> paintings[i].size >> paintings[i].value;
        normal[paintings[i].value] = 1;
    }
    for ( int i = 1; i <= m; i++ )
        cin >> frames[i];

    sort( paintings + 1, paintings + 1 + n, []( painting a, painting b ) {
        if ( a.size == b.size )
            return a.value > b.value;
        return a.size > b.size;
    } );
    sort( frames + 1, frames + 1 + m );
    int maxValue = 0;
    for ( auto p: normal )
        normal[p.first] = ++maxValue;
    for ( int i = 1; i <= n; i++ )
        paintings[i].value = normal[paintings[i].value];

    int j = m;
    dps.init( maxValue );
    for ( int i = 1; i <= n; i++ ) {
        while ( j >= 1 && frames[j] >= paintings[i].size )
            j--;
        dp[i] = min( m - j, 1 + dps.query( maxValue + 1 - paintings[i].value ) );
        dps.update( maxValue + 1 - paintings[i].value, dp[i] );
        //printf( "%d (%d %d) %d: %d\n", i, paintings[i].size, paintings[i].value, m - j, dp[i] );
    }

    cout << dps.query( maxValue ) << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...