#include <bits/stdc++.h>
using namespace std;
constexpr int NMAX = 2e5 + 5;
struct trampoline {
int x, y;
};
trampoline a[NMAX];
int R, C, N;
int dad[30][NMAX];
bool viz[NMAX];
vector <int> G[NMAX];
int T;
void Read () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> R >> C >> N;
for (int i = 1; i <= N; ++ i )
cin >> a[i].x >> a[i].y;
}
bool cmp (trampoline a, trampoline b) {
if (a.x < b.x) return false;
if (a.x == b.x && a.y < b.y) return false;
return true;
}
void Precalculare_Graf () {
sort(a+1, a+N+1, cmp);
for (int i = 1; i <= N; ++ i ) {
int st = 1, dr = i-1;
int ind = -1;
while (st <= dr) {
int mij = (st + dr) / 2;
if (a[mij].x > a[i].x+1) st = mij + 1;
else if (a[mij].x < a[i].x+1) dr = mij - 1;
else {
if (a[mij].y < a[i].y) dr = mij - 1;
else {
st = mij + 1;
ind = mij;
}
}
}
dad[0][i] = ind;
}
for (int i = 1; i <= N; ++ i ) {
if (dad[0][i] == -1) continue;
G[dad[0][i]].push_back(i);
}
}
void Build_Rmq (int node) {
viz[node] = 1;
for (int putere = 1; putere <= 20; ++ putere)
dad[putere][node] = dad[putere-1][dad[putere-1][node]];
for (auto it : G[node])
Build_Rmq(it);
}
int Who (int K, int node) {
int ans = node;
for (int putere = 0; putere <= 20 && ans != -1; ++ putere )
if ((K&(1<<putere)))
ans = dad[putere][ans];
return ans;
}
void Solve () {
cin >> T;
for (; T; -- T ) {
int x, y, End_x, End_y;
cin >> x >> y >> End_x >> End_y;
if (x > End_x) {
cout << "No" << '\n';
continue;
}
else if (x == End_x) {
if (y <= End_y)
cout << "Yes" << '\n';
else cout << "No" << '\n';
continue;
}
int st = 1, dr = N;
int ind = -1;
while (st <= dr) {
int mij = (st + dr) / 2;
if (a[mij].x > x) st = mij + 1;
else if (a[mij].x < x) dr = mij - 1;
else {
if (a[mij].y < y) dr = mij - 1;
else {
ind = mij;
st = mij+1;
}
}
}
int node = Who(End_x - x - 1, ind);
if (node != -1 && a[node].y <= End_y)
cout << "Yes\n";
else cout << "No\n";
}
}
int main()
{
Read();
Precalculare_Graf();
for (int i = 1; i <= N; ++ i )
if (!viz[i]) Build_Rmq(i);
Solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
6124 KB |
expected NO, found YES [3rd token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
121 ms |
26732 KB |
expected NO, found YES [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
250 ms |
25452 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
263 ms |
27264 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
263 ms |
27372 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
282 ms |
28300 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
280 ms |
28140 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
264 ms |
29676 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
5868 KB |
expected NO, found YES [40th token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
382 ms |
31212 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
373 ms |
29036 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Incorrect |
284 ms |
27636 KB |
expected NO, found YES [9th token] |
4 |
Halted |
0 ms |
0 KB |
- |