Submission #526214

#TimeUsernameProblemLanguageResultExecution timeMemory
526214Lam_lai_cuoc_doiTrampoline (info1cup20_trampoline)C++17
100 / 100
408 ms52508 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

template <class T>
void read(T &x)
{
    x = 0;
    register int c;
    while ((c = getchar()) && (c > '9' || c < '0'))
        ;
    for (; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + c - '0';
}

constexpr bool typetest = 0;
constexpr int N = 2e5 + 5;
int n, r, c, q;
int ranks[N], par[N][18];

pair<int, int> a[N];
vector<int> adj[N];

void Read()
{
    cin >> r >> c >> n;

    for (int i = 1; i <= n; ++i)
        cin >> a[i].first >> a[i].second;
    cin >> q;
}

void dfs(int v)
{
    for (int i = 1; i < 18; ++i)
        par[v][i] = par[par[v][i - 1]][i - 1];

    for (int i : adj[v])
        if (i != par[v][0])
        {
            par[i][0] = v;
            ranks[i] = ranks[v] + 1;
            dfs(i);
        }
}

void Solve()
{
    sort(a + 1, a + n + 1);

    for (int i = 1; i <= n; ++i)
    {
        int j = lower_bound(a + 1, a + n + 1, make_pair(a[i].first + 1, a[i].second)) - a;
        if (j > n || a[j].first != a[i].first + 1)
            adj[0].emplace_back(i);
        else
            adj[j].emplace_back(i);
    }

    dfs(0);

    while (q--)
    {
        pair<int, int> start, goal;

        cin >> start.first >> start.second >> goal.first >> goal.second;

        if (start.first > goal.first || start.second > goal.second)
        {
            cout << "No\n";
            continue;
        }

        if (start.first == goal.first)
        {
            cout << "Yes\n";
            continue;
        }

        int j = lower_bound(a + 1, a + n + 1, start) - a;

        if (j > n || a[j].first != start.first || ranks[j] < goal.first - start.first)
        {
            cout << "No\n";
            continue;
        }

        int u = ranks[j] - (goal.first - start.first) + 1, v = j;

        for (int i = 17; ~i; --i)
            if (ranks[par[v][i]] >= u)
                v = par[v][i];

        if (a[v].second > goal.second)
            cout << "No\n";
        else
            cout << "Yes\n";
    }
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen("tests.inp", "r"))
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    int t(1);
    if (typetest)
        cin >> t;
    for (int _ = 1; _ <= t; ++_)
    {
        // cout << "Case " << _ << ": ";
        Read();
        Solve();
    }
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}

/*
 */

Compilation message (stderr)

trampoline.cpp: In function 'void read(T&)':
trampoline.cpp:12:18: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 |     register int c;
      |                  ^
trampoline.cpp: In function 'int32_t main()':
trampoline.cpp:111:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
trampoline.cpp:112:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...