Submission #769801

# Submission time Handle Problem Language Result Execution time Memory
769801 2023-06-30T09:21:01 Z borisAngelov Trampoline (info1cup20_trampoline) C++17
100 / 100
333 ms 29224 KB
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int maxn = 200005;
const int max_log = 20;

int r, c, n;

pair<int, int> a[maxn];

int sorted_indexes[maxn];

int sparse[max_log][maxn];

int lifting(int start, int times)
{
    if (times >= n + 1)
    {
        return 0;
    }

    int res = start;

    for (int log = max_log - 1; log >= 0; --log)
    {
        if ((times & (1 << log)) == 0)
        {
            continue;
        }

        res = sparse[log][res];
    }

    return res;
}

int binary(int x, int y)
{
    int l = 1;
    int r = n;

    while (l <= r)
    {
        int mid = (l + r) / 2;

        if (a[sorted_indexes[mid]].first != x)
        {
            if (a[sorted_indexes[mid]].first < x)
            {
                l = mid + 1;
            }
            else
            {
                r = mid - 1;
            }
        }
        else
        {
            if (a[sorted_indexes[mid]].second < y)
            {
                l = mid + 1;
            }
            else
            {
                r = mid - 1;
            }
        }
    }

    if (a[sorted_indexes[l]].first == x && a[sorted_indexes[l]].second >= y)
    {
        return sorted_indexes[l];
    }

    return 0;
}

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fastIO();

    cin >> r >> c >> n;

    for (int i = 1; i <= n; ++i)
    {
        sorted_indexes[i] = i;
        cin >> a[i].first >> a[i].second;
    }

    sort(sorted_indexes + 1, sorted_indexes + n + 1, [&](int x, int y)
    {
        return a[x] <= a[y];
    });

    int ptr = 1;

    for (int i = 1; i <= n; ++i)
    {
        int l_idx = sorted_indexes[i];
        int r_idx = sorted_indexes[ptr];

        while (ptr <= n && (a[r_idx].first == a[l_idx].first || (a[r_idx].first == a[l_idx].first + 1 && a[r_idx].second < a[l_idx].second)))
        {
            ++ptr;
            r_idx = sorted_indexes[ptr];
        }

        if (ptr <= n && a[r_idx].first == a[l_idx].first + 1 && a[r_idx].second >= a[l_idx].second)
        {
            sparse[0][l_idx] = r_idx;
        }
        else
        {
            sparse[0][l_idx] = 0;
        }
    }

    for (int log = 1; (1 << log) <= n; ++log)
    {
        for (int i = 1; i <= n; ++i)
        {
            sparse[log][i] = sparse[log - 1][sparse[log - 1][i]];
        }
    }

    int q;
    cin >> q;

    for (int i = 1; i <= q; ++i)
    {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;

        if (x1 > x2 || y1 > y2)
        {
            cout << "No\n";
            continue;
        }

        if (x1 == x2)
        {
            cout << "Yes\n";
            continue;
        }

        int curr = binary(x1, y1);

        int res = lifting(curr, x2 - x1 - 1);

        if (curr != 0 && res != 0 && a[res].second <= y2)
        {
            cout << "Yes\n";
        }
        else
        {
            cout << "No\n";
        }
    }

    return 0;
}
/*
4 5 2
2 2
3 4
1
2 1 4 5
*/
# Verdict Execution time Memory Grader output
1 Correct 3 ms 980 KB 200 token(s): yes count is 21, no count is 179
2 Correct 3 ms 1108 KB 200 token(s): yes count is 70, no count is 130
3 Correct 2 ms 852 KB 197 token(s): yes count is 25, no count is 172
# Verdict Execution time Memory Grader output
1 Correct 58 ms 16840 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 57 ms 18508 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 59 ms 18288 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 58 ms 18600 KB 4000 token(s): yes count is 1991, no count is 2009
# Verdict Execution time Memory Grader output
1 Correct 164 ms 23464 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 163 ms 29068 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 167 ms 28964 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 174 ms 29136 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 181 ms 29032 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 177 ms 28992 KB 200000 token(s): yes count is 97163, no count is 102837
# Verdict Execution time Memory Grader output
1 Correct 4 ms 856 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 4 ms 980 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 4 ms 980 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 4 ms 984 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 4 ms 972 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 4 ms 980 KB 5000 token(s): yes count is 3390, no count is 1610
# Verdict Execution time Memory Grader output
1 Correct 282 ms 25120 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 235 ms 29048 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 175 ms 29168 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 248 ms 28980 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 203 ms 29136 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 200 ms 29108 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 185 ms 29224 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 178 ms 29088 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 227 ms 29060 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 333 ms 29060 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 263 ms 29004 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 176 ms 29152 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 174 ms 29180 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 196 ms 29112 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 193 ms 29144 KB 200000 token(s): yes count is 129674, no count is 70326