Submission #680071

# Submission time Handle Problem Language Result Execution time Memory
680071 2023-01-09T21:01:02 Z LucaLucaM Trampoline (info1cup20_trampoline) C++17
11 / 100
516 ms 29124 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] = i; /// coboram cu 2^0 = 1 nivele
    }

    for (int j=1; (1 << j) < n; j++)
    {
        for (int i=1; i<n; i++)
        {
            int pos = nxt[i][j-1]; /// coboram cu 2^(j-1) + 2^(j-1) = 2^j nivele
            pos = after_jump(a[pos].x+1, a[pos].y);

            if (pos < n)
                {
                    pos = nxt[pos][j-1];
                    nxt[i][j] = pos;
                }
            else
            {
                nxt[i][j] = n;
            }
        }
    }

    int t;
    cin >> t;

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

        if (x1 > x2 || y1 > y2)
        {
            NO;
            continue;
        }
        else
        {
            int d = x2 - x1;
            if (d == 0)
            {
                YES;
                continue;
            }

            int pos = after_jump(x1, y1);

            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 Incorrect 5 ms 1108 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 168 ms 18572 KB expected YES, found NO [3rd token]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 281 ms 29112 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 283 ms 29100 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 306 ms 29068 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 291 ms 29124 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 395 ms 29088 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 375 ms 29012 KB 200000 token(s): yes count is 97163, no count is 102837
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 980 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 516 ms 28916 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -