답안 #447458

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
447458 2021-07-26T11:33:41 Z LucaIlie Trampoline (info1cup20_trampoline) C++17
11 / 100
301 ms 27020 KB
#include <stdio.h>
#include <algorithm>

#define MAX_K 200000
#define MAX_LOG_LIN 30

using namespace std;

struct punct {
    int l, c;
};

int nxt[MAX_K][MAX_LOG_LIN + 1];
struct punct v[MAX_K];

bool cmp ( struct punct a, struct punct b ) {
    if ( a.l == b.l )
        return a.c < b.c;
    return a.l < b.l;
}

int main() {
    int n, m, k, t, lin, st, dr, mij, p, i, j;
    struct punct s, f;

    scanf( "%d%d%d", &n, &m, &k );
    for ( i = 0; i < k; i++ )
        scanf( "%d%d", &v[i].l, &v[i].c );

    sort( v, v + k, cmp );

    j = 0;
    for ( i = 0; i < k; i++ ) {
        while ( j < k && (v[j].l < v[i].l + 1 || (v[j].l == v[i].l + 1 && v[j].c <= v[i].c)) )
            j++;
        if ( j < k && v[j].l == v[i].l + 1 )
            nxt[i][0] = j;
        else
            nxt[i][0] = -1;
    }

    for ( i = 0; i < k; i++ ) {
        for ( j = 1; j <= MAX_LOG_LIN; j++ ) {
            if ( nxt[i][j - 1] != -1 )
                nxt[i][j] = nxt[nxt[i][j - 1]][j - 1];
            else
                nxt[i][j] = -1;

        }
    }

    scanf( "%d", &t );
    for ( i = 0; i < t; i++ ) {
        scanf( "%d%d%d%d", &s.l, &s.c, &f.l, &f.c );
        if ( s.l == f.l ) {
            if ( s.c <= f.c )
                printf( "Yes\n" );
            else
                printf( "No\n" );
        } else if ( f.l - s.l > k || f.l - s.l < 0 )
            printf( "No\n" );
        else {
            st = -1;
            dr = k - 1;
            while ( dr - st > 1 ) {
                mij = (st + dr) / 2;
                if ( v[mij].l < s.l || (v[mij].l == s.l && v[mij].c < s.c) )
                    st = mij;
                else
                    dr = mij;
            }
            if ( v[dr].l != s.l )
                printf( "No\n" );
            else {
                lin = f.l - s.l - 1;
                p = dr;
                for ( j = MAX_LOG_LIN; j >= 0; j-- ) {
                    if ( (lin & (1 << j)) > 0 ) {
                        if ( p != -1 )
                            p = nxt[p][j];
                    }
                }
                if ( p != -1 && v[p].l + 1 == f.l && v[p].c <= f.c )
                    printf( "Yes\n" );
                else
                    printf( "No\n" );
            }
        }
    }

    return 0;
}

Compilation message

trampoline.cpp: In function 'int main()':
trampoline.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf( "%d%d%d", &n, &m, &k );
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
trampoline.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         scanf( "%d%d", &v[i].l, &v[i].c );
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
trampoline.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     scanf( "%d", &t );
      |     ~~~~~^~~~~~~~~~~~
trampoline.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         scanf( "%d%d%d%d", &s.l, &s.c, &f.l, &f.c );
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 1356 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 123 ms 25972 KB expected YES, found NO [3rd token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 301 ms 26976 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 287 ms 27020 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 282 ms 26692 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 285 ms 26692 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 278 ms 26768 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 277 ms 26700 KB 200000 token(s): yes count is 97163, no count is 102837
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 844 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 299 ms 26736 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -