# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
447414 | LucaIlie | Trampoline (info1cup20_trampoline) | C++17 | 325 ms | 26920 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 )
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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |