Submission #365526

# Submission time Handle Problem Language Result Execution time Memory
365526 2021-02-11T19:48:20 Z jasen_penchev Trampoline (info1cup20_trampoline) C++14
100 / 100
477 ms 34156 KB
#include <algorithm>
#include <iostream>
#define endl '\n'
using namespace std;

const int MAXN = 200000;
const int LOG = 20;

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.y < b.y;
    return a.x < b.x;
}

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 + N + 1, cmp);

    for (int i = 1; i <= N; ++ i)
    {
        trampoline curr;
        curr.x = a[i].x + 1;
        curr.y = a[i].y;
        int l = 0, r = N + 1, mid;
        while (l < r - 1)
        {
            mid = (l + r) / 2;

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

        if (r == N + 1 or curr.x < a[r].x) Next[i][0] = 0;
        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 (curr.x > a[mid].x or (curr.x == a[mid].x and curr.y > a[mid].y)) l = mid;
            else r = mid;
        }

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

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

        x_start++;

        if (t == 0 or x_start > x_stop or y_start > y_stop) cout << "No" << endl;
        else cout << "Yes" << endl;
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1260 KB 200 token(s): yes count is 21, no count is 179
2 Correct 5 ms 1516 KB 200 token(s): yes count is 70, no count is 130
3 Correct 4 ms 1132 KB 197 token(s): yes count is 25, no count is 172
# Verdict Execution time Memory Grader output
1 Correct 128 ms 21484 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 136 ms 23528 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 126 ms 23020 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 146 ms 23408 KB 4000 token(s): yes count is 1991, no count is 2009
# Verdict Execution time Memory Grader output
1 Correct 304 ms 22220 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 321 ms 22380 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 298 ms 22124 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 297 ms 22268 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 305 ms 22384 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 296 ms 22252 KB 200000 token(s): yes count is 97163, no count is 102837
# Verdict Execution time Memory Grader output
1 Correct 7 ms 876 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 9 ms 1260 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 6 ms 1260 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 6 ms 1260 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 7 ms 1260 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 6 ms 1260 KB 5000 token(s): yes count is 3390, no count is 1610
# Verdict Execution time Memory Grader output
1 Correct 418 ms 22380 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 389 ms 33868 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 336 ms 34028 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 477 ms 33836 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 343 ms 33900 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 366 ms 34028 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 349 ms 34028 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 349 ms 34028 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 416 ms 33772 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 475 ms 33824 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 430 ms 34028 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 327 ms 33900 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 323 ms 34156 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 353 ms 34060 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 341 ms 33900 KB 200000 token(s): yes count is 129674, no count is 70326