Submission #521838

# Submission time Handle Problem Language Result Execution time Memory
521838 2022-02-03T09:41:31 Z LucaIlie Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
3000 ms 42168 KB
#include <bits/stdc++.h>

#define MAX_N 1000000
#define MAX_LOG_N 17
#define int long long

using namespace std;

int w[MAX_N];

int lower( int l, int r, int x ) {
    int mid;

    r++;

    while ( r - l > 1 ) {
        mid = (l + r) / 2;

        if ( w[mid] < x )
            l = mid;
        else
            r = mid;
    }

    return w[l] < x ? w[l] : -x;
}


struct AINT {
    struct nod {
        int maxEffort, maxW;
    };


    nod ans;
    nod aint[4 * MAX_N];

    void init( int nod, int l, int r ) {
        int mid;

        if ( l == r ) {
            aint[nod].maxEffort = 0;
            aint[nod].maxW = w[l];
            return;
        }

        mid = (l + r) / 2;
        init( nod * 2 + 1, l, mid );
        init( nod * 2 + 2, mid + 1, r );

        aint[nod].maxW = max( aint[nod * 2 + 1].maxW, aint[nod * 2 + 2].maxW );
        aint[nod].maxEffort = max( max( aint[nod * 2 + 1].maxEffort, aint[nod * 2 + 2].maxEffort ), aint[nod * 2 + 1].maxW + lower( mid + 1, r, aint[nod * 2 + 1].maxW ) );
       // printf( "%d %d %d %d\n", l, r, aint[nod].maxW, aint[nod].maxEffort );
    }

    void query( int nod, int l, int r, int lq, int rq ) {
        int mid;

        if ( nod == 0 )
            ans = { 0, 0 };

        if ( l > rq || r < lq )
            return;

        if ( lq <= l && r <= rq ) {
            ans.maxEffort = max( max( ans.maxEffort, aint[nod].maxEffort ), ans.maxW + lower( l, r, ans.maxW ) );
            ans.maxW = max( ans.maxW, aint[nod].maxW );
            return;
        }

        mid = (l + r) / 2;
        query( nod * 2 + 1, l, mid, lq, rq );
        query( nod * 2 + 2, mid + 1, r, lq, rq );
    }
};

AINT shelf;

signed main() {
    int n, m, l, r, k, i;

    cin >> n >> m;
    for ( i = 0; i < n; i++ )
        cin >> w[i];

    shelf.init( 0, 0, n - 1 );

    for ( i = 0; i < m; i++ ) {
        cin >> l >> r >> k;

        shelf.query( 0, 0, n - 1, l - 1, r - 1 );

        if ( shelf.ans.maxEffort > k )
            cout << "0\n";
        else
            cout << "1\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Incorrect 1 ms 308 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Incorrect 1 ms 308 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3101 ms 42168 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 317 ms 5612 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Incorrect 1 ms 308 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Incorrect 1 ms 308 KB Output isn't correct
4 Halted 0 ms 0 KB -