Submission #364294

# Submission time Handle Problem Language Result Execution time Memory
364294 2021-02-08T20:22:54 Z Alexandruabcde Trampoline (info1cup20_trampoline) C++14
100 / 100
394 ms 36764 KB
#include <bits/stdc++.h>

using namespace std;

/*
ifstream f ("trampoline.in");
ofstream g ("trampoline.out");
*/

constexpr int NMAX = 2e5 + 5;

struct trampoline {
    int x, y;
};

trampoline a[NMAX];

int R, C, N;

int dad[30][NMAX];

bool viz[NMAX];
vector <int> G[NMAX];

int T;

void Read () {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> R >> C >> N;

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

bool cmp (trampoline a, trampoline b) {
    if (a.x < b.x) return false;

    if (a.x == b.x && a.y < b.y) return false;

    return true;
}

void Precalculare_Graf () {
    sort(a+1, a+N+1, cmp);

    for (int i = 1; i <= N; ++ i ) {
        int st = 1, dr = i-1;
        int ind = -1;

        while (st <= dr) {
            int mij = (st + dr) / 2;

            if (a[mij].x > a[i].x+1) st = mij + 1;
            else if (a[mij].x < a[i].x+1) dr = mij - 1;
            else {
                if (a[mij].y < a[i].y) dr = mij - 1;
                else {
                    st = mij + 1;
                    ind = mij;
                }
            }
        }

        dad[0][i] = ind;
    }

    for (int i = 1; i <= N; ++ i ) {
        if (dad[0][i] == -1) continue;

        G[dad[0][i]].push_back(i);
    }
}

void Build_Rmq (int node) {
    viz[node] = 1;

    for (int putere = 1; putere <= 20; ++ putere)
        if (dad[putere-1][node] == -1) dad[putere][node] = -1;
        else dad[putere][node] = dad[putere-1][dad[putere-1][node]];

    for (auto it : G[node])
        Build_Rmq(it);
}

int Who (int K, int node) {
    int ans = node;

    for (int putere = 0; putere <= 20 && ans != -1; ++ putere )
        if ((K&(1<<putere)))
            ans = dad[putere][ans];

    return ans;
}

void Solve () {
    cin >> T;
    for (; T; -- T ) {
        int x, y, End_x, End_y;

        cin >> x >> y >> End_x >> End_y;

        if (x > End_x) {
            cout << "No" << '\n';
            continue;
        }
        else if (x == End_x) {
            if (y <= End_y)
                cout << "Yes" << '\n';
            else cout << "No" << '\n';

            continue;
        }

        int st = 1, dr = N;
        int ind = -1;
        while (st <= dr) {
            int mij = (st + dr) / 2;

            if (a[mij].x > x) st = mij + 1;
            else if (a[mij].x < x) dr = mij - 1;
            else {
                if (a[mij].y < y) dr = mij - 1;
                else {
                    ind = mij;
                    st = mij+1;
                }
            }
        }

        int node = Who(End_x - x - 1, ind);

        if (node != -1 && a[node].y <= End_y)
            cout << "Yes\n";
        else cout << "No\n";
    }
}

int main()
{
    Read();

    Precalculare_Graf();

    for (int i = 1; i <= N; ++ i )
        if (!viz[i]) Build_Rmq(i);

    Solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6252 KB 200 token(s): yes count is 21, no count is 179
2 Correct 9 ms 6380 KB 200 token(s): yes count is 70, no count is 130
3 Correct 7 ms 5996 KB 197 token(s): yes count is 25, no count is 172
# Verdict Execution time Memory Grader output
1 Correct 120 ms 26476 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 125 ms 26604 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 128 ms 28908 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 128 ms 26732 KB 4000 token(s): yes count is 1991, no count is 2009
# Verdict Execution time Memory Grader output
1 Correct 245 ms 25580 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 261 ms 27116 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 265 ms 27244 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 284 ms 28012 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 285 ms 28140 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 268 ms 29548 KB 200000 token(s): yes count is 97163, no count is 102837
# Verdict Execution time Memory Grader output
1 Correct 10 ms 5740 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 10 ms 5868 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 9 ms 5740 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 10 ms 5868 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 12 ms 5868 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 10 ms 5740 KB 5000 token(s): yes count is 3390, no count is 1610
# Verdict Execution time Memory Grader output
1 Correct 380 ms 30828 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 373 ms 28684 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 292 ms 27372 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 385 ms 36764 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 333 ms 29704 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 279 ms 27244 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 279 ms 27500 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 310 ms 27372 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 379 ms 29804 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 394 ms 30444 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 390 ms 33004 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 258 ms 25324 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 260 ms 25452 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 334 ms 28140 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 264 ms 27248 KB 200000 token(s): yes count is 129674, no count is 70326