#include <bits/stdc++.h>
using namespace std;
#define int long long
#define in(s, v) (s.lower_bound(v) != s.end() && *s.lower_bound(v) == v)
vector<vector<int>> adjlist, twok;
void dfs(int x, int p)
{
for (int k = 0; k < 19; k++)
{
if (twok[k][x] == -1) break;
twok[k + 1][x] = twok[k][twok[k][x]];
}
for (int i : adjlist[x])
{
if (i == p) continue;
twok[0][i] = x;
dfs(i, x);
}
}
int kances(int k, int x)
{
for (int i = 0; i < 20; i++)
{
if (x == -1) break;
if (k & (1LL << i)) x = twok[i][x];
}
return x;
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N, R, C, T, a, b, counter = 0, c, d, x;
cin >> R >> C >> N;
adjlist = vector<vector<int>>(N, vector<int>());
twok = vector<vector<int>>(20, vector<int>(N, -1));
map<int, set<pair<int, int>>> green;
set<int> visited;
vector<pair<int, int>> greens;
vector<int> subroots;
for (int i = 0; i < N; i++)
{
cin >> a >> b;
a--, b--;
if (!in(visited, a))
{
visited.insert(a);
green[a] = set<pair<int, int>>();
}
green[a].insert(pair<int, int>(b, counter));
greens.push_back(pair<int, int>(b, a));
counter++;
}
for (auto i : green)
{
for (auto j : i.second)
{
if (!in(visited, i.first + 1))
{
subroots.push_back(j.second);
continue;
}
if (green[i.first + 1].lower_bound(pair<int, int>(j.first, 0)) == green[i.first + 1].end())
{
subroots.push_back(j.second);
continue;
}
x = green[i.first + 1].lower_bound(pair<int, int>(j.first, 0))->second;
adjlist[j.second].push_back(x);
adjlist[x].push_back(j.second);
}
}
for (int i : subroots) dfs(i, -1);
cin >> T;
for (int i = 0; i < T; i++)
{
cin >> a >> b >> c >> d;
a--, b--, c--, d--;
swap(a, b);
swap(c, d);
if (a > c || b > d)
{
cout << "No\n";
continue;
}
if (b == d)
{
cout << "Yes\n";
continue;
}
if (!in(visited, b))
{
cout << "No\n";
continue;
}
if (green[b].lower_bound(pair<int, int>(a, 0)) == green[b].end())
{
cout << "No\n";
continue;
}
x = green[b].lower_bound(pair<int, int>(a, 0))->second;
x = kances(d - b - 1, x);
if (x == -1)
{
cout << "No\n";
continue;
}
cout << (greens[x].first <= c ? "Yes\n" : "No\n");
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
3028 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
8 ms |
3288 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
5 ms |
2392 KB |
197 token(s): yes count is 25, no count is 172 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
243 ms |
61908 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
277 ms |
62516 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
240 ms |
60824 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
249 ms |
61800 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
371 ms |
78628 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
387 ms |
75060 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
400 ms |
71984 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
475 ms |
72064 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
521 ms |
71988 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
714 ms |
84312 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2136 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
7 ms |
2140 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
9 ms |
2652 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
6 ms |
2140 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
9 ms |
2396 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
6 ms |
2396 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1004 ms |
87012 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
759 ms |
75448 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
453 ms |
72196 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
1146 ms |
108068 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
763 ms |
91328 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
550 ms |
75100 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
452 ms |
75056 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
505 ms |
73008 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
937 ms |
85384 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
965 ms |
84132 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
1112 ms |
96368 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
427 ms |
77984 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
436 ms |
78512 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
568 ms |
72652 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
429 ms |
75824 KB |
200000 token(s): yes count is 129674, no count is 70326 |