Submission #1050511

# Submission time Handle Problem Language Result Execution time Memory
1050511 2024-08-09T10:20:42 Z LucaIlie Fire (BOI24_fire) C++17
0 / 100
2 ms 4440 KB
#include <bits/stdc++.h>

using namespace std;

struct interval {
    int l, r;
};

struct maxpos {
    int max, pos;

    bool operator < ( const maxpos &x ) const {
        return max < x.max;
    }
};

const int MAX_N = 2e5;
const int MAX_VAL = 4 * MAX_N;
const int MAX_LOG_N = 17;
const int MAX_LOG_VAL = MAX_LOG_N + 2;
int nxt[MAX_LOG_N + 2][2 * MAX_N];
interval v[2 * MAX_N];
maxpos maxR[MAX_LOG_VAL + 1][MAX_VAL];
map<int, int> normal;

int main() {
    int n, m;

    cin >> n >> m;
    for ( int i = 0; i < n; i++ ) {
        int l, r;
        cin >> l >> r;
        if ( l > r )
            r += m;
        v[i] = { l, r };
        v[i + n] = { l + m, r + m };
        normal[l] = 0;
        normal[l + m] = 0;
        normal[r] = 0;
        normal[r + m] = 0;
    }
    n *= 2;

    int val = 0;
    for ( auto x: normal )
        normal[x.first] = val++;

    //for ( int i = 0; i < n; i++ )
      //  printf( "%d %d\n", v[i].l, v[i].r );

    for ( int i = 0; i < n; i++ )
        maxR[0][normal[v[i].l]] = max( maxR[0][normal[v[i].l]], { v[i].r, i } );
    for ( int l = 1; (1 << l) <= val; l++ ) {
        for ( int i = 0; i <= val - (1 << l); i++ )
            maxR[l][i] = max( maxR[l - 1][i], maxR[l - 1][i + (1 << (l - 1))] );
    }

    for ( int i = 0; i < n; i++ ) {
        int l = log2( normal[v[i].r] - normal[v[i].l] );
        nxt[0][i] = max( maxR[l][normal[v[i].l]], maxR[l][normal[v[i].r] - (1 << l) + 1] ).pos;
    }
    for ( int l = 1; (1 << l) <= n; l++ ) {
        for ( int i = 0; i < n; i++ )
            nxt[l][i] = nxt[l - 1][nxt[l - 1][i]];
    }

    int minLen = n + 1;
    for ( int i = 0; i < n; i++ ) {
        int p = i, len = 1;
        while ( v[p].r < v[i].l + m && p != nxt[0][p] ) {
            p = nxt[0][p];
            len++;
        }
        if ( v[p].r >= v[i].l + m )
            minLen = min( minLen, len );
    }
    /*for ( int i = 0; i < n; i++ ) {
        int len = 0, p = i;
        for ( int l = log2( n ); l >= 0; l-- ) {
            if ( v[nxt[l][p]].r < v[i].l + m ) {
                p = nxt[l][p];
                len += (1 << p);
            }
        }
        p = nxt[0][p];
        len++;

        if ( v[p].r >= v[i].l + m )
            minLen = min( minLen, len );
    }*/

    cout << (minLen == n + 1 ? -1 : minLen);

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 440 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Runtime error 2 ms 540 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 440 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Runtime error 2 ms 540 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 440 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Runtime error 2 ms 540 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# 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 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 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 Incorrect 1 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 440 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Runtime error 2 ms 540 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -