Submission #680076

# Submission time Handle Problem Language Result Execution time Memory
680076 2023-01-09T21:08:36 Z LucaLucaM Trampoline (info1cup20_trampoline) C++17
100 / 100
358 ms 29244 KB
#include <bits/stdc++.h>

using namespace std;

map<int, vector<int>>lin;

#define YES cout << "Yes\n"
#define NO cout << "No\n"

int n;

int nxt[200005][19]; /// nxt[i] - urmatoarea trambulina dupa a[i]

struct trambulina
{
    int x, y;

    bool operator < (const trambulina aux) const
    {
        if (x == aux.x)
            return y < aux.y;
        return x < aux.x;
    }
};

trambulina a[200005];

int after_jump (int x, int y)
{
    int l=1, r=n;
    int sol = n + 1;

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

        if (a[mid].x < x)
            l = mid + 1 ;
        else if (a[mid].x > x)
            r = mid - 1;
        else
        {
            if (a[mid].y >= y)
                sol = mid, r = mid-1;
            else
                l = mid + 1;
        }
    }

    return sol;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int r, c;
    cin >> r >> c >> n;

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

    sort(a+1, a+n+1);
    a[++n] = {r+1, c+1};

    /**
    nxt[i] - urmatoarea trambulina
    **/

    for (int i=1; i<=n; i++)
    {
        nxt[i][0] = after_jump(a[i].x+1, a[i].y);
    }

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

    int t;
    cin >> t;

    while (t--)
    {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;

        if (x1 > x2 || y1 > y2 || x2 - x1 > n)
        {
            NO;
            continue;
        }
        else if (x1 == x2)
            YES;
        else
        {
            int d = x2 - x1 - 1;
            int pos = after_jump(x1, y1);

            if (a[pos].x != x1)
            {
                NO;
                continue;
            }

            for (int b=0; b<18; b++)
            {
                if (d & (1 << b))
                {
                    pos = nxt[pos][b];
                }
            }

            if (pos >= n)
            {
                NO;
                continue;
            }

            if (a[pos].x + 1 == x2 && a[pos].y <= y2)
                YES;
            else
                NO;
        }
    }

    return 0;
}
# 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 5 ms 1104 KB 200 token(s): yes count is 70, no count is 130
3 Correct 4 ms 852 KB 197 token(s): yes count is 25, no count is 172
# Verdict Execution time Memory Grader output
1 Correct 90 ms 16736 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 103 ms 18504 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 94 ms 18248 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 99 ms 18580 KB 4000 token(s): yes count is 1991, no count is 2009
# Verdict Execution time Memory Grader output
1 Correct 196 ms 17456 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 201 ms 17364 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 197 ms 17412 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 203 ms 17360 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 209 ms 17332 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 217 ms 17320 KB 200000 token(s): yes count is 97163, no count is 102837
# Verdict Execution time Memory Grader output
1 Correct 4 ms 724 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 5 ms 980 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 5 ms 1044 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 7 ms 972 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 7 ms 980 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 5 ms 1008 KB 5000 token(s): yes count is 3390, no count is 1610
# Verdict Execution time Memory Grader output
1 Correct 286 ms 17504 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 268 ms 29064 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 208 ms 29104 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 341 ms 29192 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 236 ms 29088 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 229 ms 29120 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 228 ms 29132 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 219 ms 29172 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 328 ms 28956 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 337 ms 29120 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 358 ms 29144 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 208 ms 29084 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 217 ms 29244 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 242 ms 29108 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 226 ms 29196 KB 200000 token(s): yes count is 129674, no count is 70326