#include <bits/stdc++.h>
#define int long long
#define float double
#define pb push_back
#define F first
#define S second
#define T int t; cin >> t; while(t--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int inf = 8e18;
const int N = 1e6 + 6;
const int M = 1e3 + 3;
const int LOG = 31;
const int mod = 1e9 + 7;
const float pi = atan(1) * 4;
map<int, set<int>> mp;
map<int, set<int>> rmp;
map<int, map<int, int>> num;
map<int, int> getx;
int n, c, r;
int sparce[N][LOG];
void build()
{
for(auto y: mp)
{
for(auto x: y.S)
sparce[num[y.F][x]][0] = num[y.F - 1][*mp[y.F - 1].lower_bound(x)];
}
for(int j = 1; j < LOG; j++)
{
for(auto y: mp)
{
for(auto x: y.S)
{
int me = num[y.F][x];
int xx = sparce[me][j - 1];
sparce[me][j] = sparce[xx][j - 1];
}
}
}
}
main()
{
IOS
cin >> r >> c >> n;
for(int i = 1; i <= n; i++)
{
int x, y;
cin >> y >> x;
getx[i] = x;
mp[y].insert(x);
rmp[y].insert(-x);
num[y][x] = i;
}
build();
T
{
int y, x, yy, xx;
cin >> y >> x >> yy >> xx;
if (y == yy)
{
cout << "Yes\n";
continue;
}
auto stop = rmp[yy - 1].lower_bound(-xx);
auto start = mp[y].lower_bound(x);
if (stop == rmp[yy - 1].end() || start == mp[y].end())
{
cout << "No\n";
continue;
}
x = *start;
xx = *stop;
yy--;
int me = num[yy][xx];
int j = LOG - 1;
while((1 << j) > yy - y)
j--;
while(yy > y)
{
yy -= (1 << j);
xx = sparce[me][j];
me = num[yy][xx];
if (me == 0)
{
y = -inf;
x = -inf;
break;
}
}
if (xx >= x)
cout << "Yes\n";
else
cout << "No\n";
}
}
/*
4 5 2
2 2
3 4
3
2 1 4 5
1 2 1 4
2 3 4 4
*/
Compilation message
trampoline.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
46 | main()
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
42 ms |
4476 KB |
expected NO, found YES [2nd token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1940 ms |
95740 KB |
expected NO, found YES [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2031 ms |
101900 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
29 ms |
3012 KB |
expected NO, found YES [2nd token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2080 ms |
128724 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |