답안 #699910

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
699910 2023-02-18T09:32:35 Z KiriLL1ca Trampoline (info1cup20_trampoline) C++17
100 / 100
1071 ms 81552 KB
#include <bits/stdc++.h>
#define fr first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\n'
#define sz(x) (int)((x).size())
#define vec vector

using namespace std;

template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;

inline void solve () {
    int R, C, n; cin >> R >> C >> n;
    const int lg = 31;

    vec <pii> gr (n);
    map <int, vector <int>> mp;
    for (auto &[x, y] : gr) {
        cin >> x >> y;
        mp[x].pb(y);
    }
    for (auto &[_, y] : mp) sort(all(y));
    sort(all(gr));

    vec <vec <int>> up (n, vec <int> (lg));
    /// up[i][j] = p
    /// x[p] = x[i] + 2^j
    /// y[p] > y[i], y[p] -> min

    map <pii, int> cp;
    for (int i = 0; i < n; ++i) {
        auto [x, y] = gr[i]; cp[gr[i]] = i;
        auto it = lower_bound(all(gr), make_pair(x + 1, y));
        if (it == gr.end() || it->fr != x + 1) up[i][0] = -1;
        else up[i][0] = (it - gr.begin());
    }

    for (int i = 1; i < lg; ++i) {
        for (int j = 0; j < n; ++j) {
            if (!~up[j][i - 1]) up[j][i] = -1;
            else up[j][i] = up[up[j][i - 1]][i - 1];
        }
    }

    auto yes = [&] () { cout << "Yes" << endl; };
    auto no = [&] () { cout << "No" << endl; };

    int q; cin >> q;
    while (q--) {
        int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
        if (x1 == x2) {
            if (y1 <= y2) yes();
            else no();
            continue;
        }
        if (x1 > x2) {
            no();
            continue;
        }
        if (!sz(mp[x1])) {
            no();
            continue;
        }

        auto it = lower_bound(all(mp[x1]), y1);
        if (it == mp[x1].end()) {
            no();
            continue;
        }

        int go = cp[{x1, *it}], D = x2 - x1 - 1;
        for (int p = lg - 1; ~p && ~go; --p) {
            if (D >> p & 1) go = up[go][p];
        }
        if (~go && gr[go].fr + 1 == x2 && gr[go].sc <= y2) yes();
        else no();
    }
}

signed main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif// LOCAL
    int t = 1; //cin >> t;
    while (t--) solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 2516 KB 200 token(s): yes count is 21, no count is 179
2 Correct 9 ms 2800 KB 200 token(s): yes count is 70, no count is 130
3 Correct 7 ms 2000 KB 197 token(s): yes count is 25, no count is 172
# 결과 실행 시간 메모리 Grader output
1 Correct 229 ms 50580 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 235 ms 50624 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 233 ms 49944 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 262 ms 50680 KB 4000 token(s): yes count is 1991, no count is 2009
# 결과 실행 시간 메모리 Grader output
1 Correct 529 ms 60592 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 513 ms 60552 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 511 ms 60596 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 635 ms 61000 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 719 ms 60996 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 747 ms 67084 KB 200000 token(s): yes count is 97163, no count is 102837
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1748 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 9 ms 1856 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 10 ms 2260 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 8 ms 1756 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 11 ms 1920 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 8 ms 1832 KB 5000 token(s): yes count is 3390, no count is 1610
# 결과 실행 시간 메모리 Grader output
1 Correct 945 ms 68404 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 812 ms 63052 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 591 ms 60724 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 1071 ms 81552 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 712 ms 67932 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 568 ms 60684 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 585 ms 60500 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 595 ms 60588 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 950 ms 67096 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 973 ms 67028 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 1065 ms 74280 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 579 ms 60420 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 590 ms 60632 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 682 ms 60984 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 537 ms 60456 KB 200000 token(s): yes count is 129674, no count is 70326