Submission #374672

# Submission time Handle Problem Language Result Execution time Memory
374672 2021-03-07T20:18:19 Z Alex_tz307 Trampoline (info1cup20_trampoline) C++17
100 / 100
543 ms 39660 KB
#include <bits/stdc++.h>

using namespace std;

class coord {
    public:
        int x, y;

        bool operator < (const coord &A) const {
            if(x != A.x)
                return x < A.x;
            return y < A.y;
        }

        bool operator > (const coord &A) const {
            if(x != A.x)
                return x > A.x;
            return y > A.y;
        }
};

const int NMAX = 2e5 + 5;
int R, C, N, Q, ancestor[NMAX][32];
coord a[NMAX];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> R >> C >> N;
    for(int i = 1; i <= N; ++i)
        cin >> a[i].x >> a[i].y;
    sort(a + 1, a + N + 1);
    for(int i = 2; i <= N; ++i) {
        int st = 1, dr = N, prv_line = a[i].x - 1, l = -1, r = -1;
        while(st <= dr) {
            int mid = (st + dr) >> 1;
            if(a[mid].x >= prv_line) {
                l = mid;
                dr = mid - 1;
            }
            else
                st = mid + 1;
        }
        st = 1, dr = N;
        while(st <= dr) {
            int mid = (st + dr) >> 1;
            if(a[mid].x <= prv_line) {
                r = mid;
                st = mid + 1;
            }
            else
                dr = mid - 1;
        }
        if(l == -1 || r == -1 || a[l].x != prv_line || a[r].x != prv_line)
            continue;
        int ans = -1;
        while(l <= r) {
            int mid = (l + r) >> 1;
            if(a[mid].y <= a[i].y) {
                ans = mid;
                l = mid + 1;
            }
            else
                r = mid - 1;
        }
        if(ans != -1)
            ancestor[i][0] = ans;
    }
    for(int level = 1; level < 31; ++level)
        for(int i = 1; i <= N; ++i)
            ancestor[i][level] = ancestor[ancestor[i][level - 1]][level - 1];
    cin >> Q;
    for(int q = 0; q < Q; ++q) {
        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;
        }
        --x2;
        int ans = -1, st = 1, dr = N;
        while(st <= dr) {
            int mid = (st + dr) >> 1;
            if(a[mid] > coord{x2, y2})
                dr = mid - 1;
            else {
                if(a[mid].x == x2)
                    ans = mid;
                st = mid + 1;
            }
        }
        if(ans == -1 || a[ans].y < y1 || a[ans].y > y2) {
            cout << "No\n";
            continue;
        }
        for(int level = 30; level >= 0; --level) {
            int father = ancestor[ans][level];
            if(a[father].x >= x1)
                ans = father;
        }
        if(a[ans].x == x1 && a[ans].y >= y1)
            cout << "Yes\n";
        else
            cout << "No\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1516 KB 200 token(s): yes count is 21, no count is 179
2 Correct 5 ms 1792 KB 200 token(s): yes count is 70, no count is 130
3 Correct 4 ms 1388 KB 197 token(s): yes count is 25, no count is 172
# Verdict Execution time Memory Grader output
1 Correct 152 ms 28792 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 153 ms 28780 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 150 ms 28524 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 162 ms 28848 KB 4000 token(s): yes count is 1991, no count is 2009
# Verdict Execution time Memory Grader output
1 Correct 339 ms 39488 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 331 ms 39404 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 326 ms 39276 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 332 ms 39492 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 330 ms 39404 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 343 ms 39216 KB 200000 token(s): yes count is 97163, no count is 102837
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1388 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 7 ms 1388 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 7 ms 1388 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 7 ms 1388 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 7 ms 1388 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 6 ms 1516 KB 5000 token(s): yes count is 3390, no count is 1610
# Verdict Execution time Memory Grader output
1 Correct 496 ms 39616 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 444 ms 39440 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 339 ms 39660 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 543 ms 39404 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 407 ms 39404 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 335 ms 39404 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 330 ms 39404 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 344 ms 39516 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 467 ms 39276 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 498 ms 39532 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 533 ms 39404 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 321 ms 39404 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 310 ms 39404 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 375 ms 39660 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 325 ms 39532 KB 200000 token(s): yes count is 129674, no count is 70326