#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#define endl '\n'
#define fi first
#define se second
#define lsb(x) (x & (-x))
using namespace std;
const int NMAX = 2e5+5;
const int LOGN = 22;
struct Point {
int x, y;
};
int n;
Point a[NMAX];
map<int, map<int, int>> mp;
int dp[LOGN][NMAX];
void read() {
int r, c;
cin >> r >> c >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].x >> a[i].y;
mp[a[i].x][a[i].y] = i;
}
}
void precalc() {
for (int i = 1; i <= n; i++) {
auto it = mp[a[i].x + 1].lower_bound(a[i].y);
if (it != mp[a[i].x + 1].end())
dp[0][i] = it->se;
}
for (int j = 1; 1 << j <= n; j++) {
for (int i = 1; i <= n; i++)
dp[j][i] = dp[j - 1][dp[j - 1][i]];
}
}
int jump(int u, int k) {
if (k > n) return 0;
if (k == 0) return u;
return jump(dp[int(log2(lsb(k)))][u], k ^ lsb(k));
}
Point jump(int x, int y, int k) {
auto it = mp[x].lower_bound(y);
if (it == mp[x].end()) return { };
return a[jump(it->se, k)];
}
bool query(int x1, int y1, int x2, int y2) {
if (x2 < x1 || y2 < y1) return false;
if (x1 == x2) return true;
Point p = jump(x1, y1, x2 - x1 - 1);
if (!p.x) return false;
return p.y <= y2;
}
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
read();
precalc();
int t = 1;
cin >> t;
while (t--) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << (query(x1, y1, x2, y2) ? "Yes" : "No") << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
13144 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
6 ms |
13148 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
5 ms |
13148 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
147 ms |
26776 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
148 ms |
26712 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
165 ms |
26708 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
144 ms |
26704 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
240 ms |
27216 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
246 ms |
27456 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
250 ms |
27220 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
286 ms |
27564 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
265 ms |
27272 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
385 ms |
33384 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
12888 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
6 ms |
12892 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
9 ms |
13916 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
6 ms |
13148 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
7 ms |
13404 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
6 ms |
13148 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
515 ms |
34900 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
387 ms |
29008 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
274 ms |
27220 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
636 ms |
45980 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
397 ms |
33924 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
284 ms |
27124 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
264 ms |
27216 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
277 ms |
27216 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
472 ms |
33420 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
486 ms |
33560 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
595 ms |
39924 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
223 ms |
27220 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
258 ms |
27336 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
314 ms |
27216 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
258 ms |
27712 KB |
200000 token(s): yes count is 129674, no count is 70326 |