Submission #835047

# Submission time Handle Problem Language Result Execution time Memory
835047 2023-08-23T06:59:11 Z alex_2008 Trampoline (info1cup20_trampoline) C++14
100 / 100
1272 ms 81452 KB
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#define int long long
using namespace std;
const int N = 2e5 + 10;
map <int, vector<int>> mp;
map <pair<int, int>, int> yp;
vector <pair<int, int>> v;
int a[N];
int dp[N][20];
int ans(int x, int y, int cnt) {
    int u = yp[{x, y}];
    for (int i = 19; i >= 0; i--) {
        if (cnt & (1 << i)) u = dp[u][i];
        if (u == -1) return 1e9 + 10;
    }
    return v[u].second;
}
signed main()
{
    int r, c, n;
    cin >> r >> c >> n;
    for (int i = 1; i <= n; i++) {
        int a, b;
        cin >> a >> b;
        mp[a].push_back(b);
    }
    for (auto &it : mp) {
        sort(it.second.begin(), it.second.end());
    }
    int cnt = -1;
    for (auto it : mp) {
        for (auto j : it.second) {
            v.push_back({ it.first, j });
            yp[{it.first, j}] = ++cnt;
        }
    }
    for (int i = n - 1; i >= 0; i--) {
        if (v[i].first == v.back().first) {
            for (int j = 0; j <= 19; j++) {
                dp[i][j] = -1;
            }
        }
        else {
            auto it = mp.find(v[i].first); it++;
            if (it->first > v[i].first + 1) dp[i][0] = -1;
            else if (it->second.back() < v[i].second) dp[i][0] = -1;
            else {
                int k = lower_bound(it->second.begin(), it->second.end(), v[i].second) - it->second.begin();
                dp[i][0] = yp[{v[i].first + 1, it->second[k]}];
            }
            for (int j = 1; j <= 19; j++) {
                if (dp[i][j - 1] == -1) {
                    dp[i][j] = -1;
                    continue;
                }
                dp[i][j] = dp[dp[i][j - 1]][j - 1];
            }
        }
    }
    int q;
    cin >> q;
    while (q--) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
      	if (a > c || b > d) {
        	cout << "No\n";
          	continue;
        }
        if (a == c) {
            cout << "Yes\n";
            continue;
        }
        if (mp.find(a) == mp.end()) {
            cout << "No\n";
            continue;
        }
        auto it = mp.find(a);
        if (it->second.back() < b) {
            cout << "No\n";
            continue;
        }
        int j = lower_bound(it->second.begin(), it->second.end(), b) - it->second.begin();
        int l = ans(a, it->second[j], c - a - 1);
        if (l <= d) cout << "Yes\n";
        else cout << "No\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2532 KB 200 token(s): yes count is 21, no count is 179
2 Correct 7 ms 2768 KB 200 token(s): yes count is 70, no count is 130
3 Correct 5 ms 2004 KB 197 token(s): yes count is 25, no count is 172
# Verdict Execution time Memory Grader output
1 Correct 184 ms 50016 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 184 ms 50108 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 163 ms 49332 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 184 ms 50124 KB 4000 token(s): yes count is 1991, no count is 2009
# Verdict Execution time Memory Grader output
1 Correct 736 ms 49824 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 760 ms 49600 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 736 ms 49880 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 794 ms 50468 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 749 ms 50368 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 917 ms 56512 KB 200000 token(s): yes count is 97163, no count is 102837
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1492 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 17 ms 1876 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 17 ms 2260 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 16 ms 1876 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 18 ms 2004 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 16 ms 1876 KB 5000 token(s): yes count is 3390, no count is 1610
# Verdict Execution time Memory Grader output
1 Correct 1083 ms 57808 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 895 ms 52472 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 725 ms 61628 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 1272 ms 81452 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 926 ms 69180 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 846 ms 61356 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 816 ms 61368 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 726 ms 61416 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 1020 ms 68212 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 1088 ms 68472 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 1239 ms 74320 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 733 ms 61744 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 737 ms 61608 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 783 ms 62148 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 739 ms 61704 KB 200000 token(s): yes count is 129674, no count is 70326