답안 #365510

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
365510 2021-02-11T19:03:44 Z jasen_penchev Trampoline (info1cup20_trampoline) C++14
0 / 100
163 ms 44396 KB
#include <algorithm>
#include <iostream>
#define endl '\n'
using namespace std;

const int MAXN = 200000;
const int LOG = 18;

struct trampoline
{
    int x, y;
};

trampoline a[MAXN + 5];
int Next[MAXN + 5][LOG + 5];

bool cmp(trampoline a, trampoline b)
{
    if (a.x != b.x) return a.x < b.x;
    return a.y < b.y;
}

int main()
{
    ios :: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int R, C, N;
    cin >> R >> C >> N;

    for (int i = 1; i <= N; ++ i)
    {
        cin >> a[i].x >> a[i].y;
    }

    sort(a + 1, a + 1 + N, cmp);

    for (int i = 1; i <= N; ++ i)
    {
        int l = i, r = N + 1, mid;
        while (l < r - 1)
        {
            mid = (l + r) / 2;

            if (a[i].x == a[mid].x or (a[i].x + 1 == a[mid].x and a[i].y > a[mid].y)) l = mid;
            else r = mid;
        }

        if (r == N + 1 or a[i].x + 1 != a[mid].x) Next[i][0] = -1;
        else Next[i][0] = r;
    }

    for (int j = 1; j <= LOG; ++ j)
    {
        for (int i = 1; i <= N; ++ i)
        {
            Next[i][j] = Next[Next[i][j - 1]][j - 1];
        }
    }

    int T;
    cin >> T;
    for (int i = 1; i <= T; ++ i)
    {
        int x_start, y_start, x_stop, y_stop;
        cin >> x_start >> y_start >> x_stop >> y_stop;

        if (x_start > x_stop or (x_start == x_stop and y_start > y_stop))
        {
            cout << "No" << endl;
            continue;
        }
        if (x_start == x_stop)
        {
            cout << "Yes" << endl;
            continue;
        }

        trampoline curr;
        curr.x = x_start;
        curr.y = y_start;
        int l = 0, r = N + 1, mid;
        while (l < r - 1)
        {
            mid = (l + r) / 2;

            if (cmp(curr, a[mid])) r = mid;
            else l = mid;
        }

        if (r == N + 1 or a[r].x > x_start)
        {
            cout << "No" << endl;
            continue;
        }

        x_start = a[r].x;
        y_start = a[r].y;

        int t;
        for (int j = LOG; j >= 0; -- j)
        {
            if (x_start + (1ll << j) <= x_stop)
            {
                t = Next[x_start][j];
                if (t == -1) break;
                x_start = a[t].x;
                y_start = a[t].y;
            }
        }

        if (t == -1 or y_start > y_stop) cout << "No" << endl;
        else cout << "Yes" << endl;
    }

    return 0;
}

Compilation message

trampoline.cpp: In function 'int main()':
trampoline.cpp:112:9: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
  112 |         if (t == -1 or y_start > y_stop) cout << "No" << endl;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1260 KB expected NO, found YES [2nd token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 119 ms 21740 KB expected NO, found YES [1st token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 163 ms 44140 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 1772 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 156 ms 44396 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -