Submission #447466

#TimeUsernameProblemLanguageResultExecution timeMemory
447466LucaIlieTrampoline (info1cup20_trampoline)C++17
57 / 100
462 ms27112 KiB
#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 ); for ( i = 0; i < k; i++ ) { st = -1; dr = k - 1; while ( dr - st > 1 ) { mij = (st + dr) / 2; if ( v[mij].l < v[i].l + 1 || (v[mij].l == v[i].l + 1 && v[mij].c <= v[i].c) ) st = mij; else dr = mij; } if ( v[dr].l == v[i].l + 1 && v[dr].c > v[i].c ) nxt[i][0] = dr; else nxt[i][0] = -1; } for ( j = 1; j <= MAX_LOG_LIN; j++ ) { for ( i = 0; i < k; i++ ) { 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 (stderr)

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:58:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |     scanf( "%d", &t );
      |     ~~~~~^~~~~~~~~~~~
trampoline.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         scanf( "%d%d%d%d", &s.l, &s.c, &f.l, &f.c );
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...