#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
vector<int> adj[MAXN];
int p[MAXN][20], depth[MAXN], grp[MAXN];
void dfs(int x, int g, int d, int par) {
grp[x] = g;
depth[x] = d;
p[x][0] = par;
for(int i = 1; i < 20; i++) {
if(p[x][i-1] == -1) break;
p[x][i] = p[p[x][i-1]][i-1];
}
for(int i : adj[x]) if(i != par) dfs(i, g, d+1, x);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
memset(p, -1, sizeof(p));
int r, c, n, x1, y1, x2, y2;
cin >> r >> c >> n;
pair<int, int> a[n];
for(int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
sort(a, a+n);
//for(int i = 0; i < n-1; i++) if(a[i].first == a[i+1].first) adj[i].push_back(i+1);
map<int, set<pair<int, int>>> m;
for(int i = 0; i < n; i++) {
m[a[i].first].insert({a[i].second, i});
}
int tmp[n];
memset(tmp, 0, sizeof(tmp));
for(int i = 0; i < n; i++) {
if(m.find(a[i].first+1) == m.end()) continue;
auto it = m[a[i].first+1].lower_bound({a[i].second, 0});
if(it == m[a[i].first+1].end()) continue;
adj[it->second].push_back(i);
tmp[i] = 1;
}
for(int i = 0; i < n; i++) if(tmp[i] == 0) dfs(i, i, 0, -1);
int q;
cin >> q;
while(q--) {
cin >> x1 >> y1 >> x2 >> y2;
if(x1 > x2 || y1 > y2) {
cout << "No" << '\n';
continue;
}
if(x1 == x2) {
cout << "Yes" << '\n';
continue;
}
if(m.find(x1) == m.end()) {
cout << "No" << '\n';
continue;
}
if(m.find(x2-1) == m.end()) {
cout << "No" << '\n';
continue;
}
auto it = m[x1].lower_bound({y1, 0});
auto it2 = m[x2-1].lower_bound({y2+1, 0});
if(it == m[x1].end()) {
cout << "No" << '\n';
continue;
}
if(it2 == m[x2-1].begin()) {
cout << "No" << '\n';
continue;
}
it2--;
int h = x2-1-x1;
int cur = it->second;
for(int i = 0; i < 20; i++) {
if(h&(1<<i)) cur = p[cur][i];
if(cur == -1) {
cout << "No" << '\n';
goto ed;
}
}
if(a[cur].second <= a[it2->second].second) cout << "Yes" << '\n';
else cout << "No" << '\n';
ed:;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
22872 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
8 ms |
22876 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
7 ms |
22620 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
37588 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
108 ms |
37568 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
110 ms |
39548 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
106 ms |
37716 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
270 ms |
36036 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
301 ms |
37880 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
239 ms |
37968 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
321 ms |
38948 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
293 ms |
39104 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
358 ms |
48520 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
22620 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
10 ms |
22500 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
10 ms |
23008 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
9 ms |
22600 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
10 ms |
22876 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
9 ms |
22456 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
552 ms |
51944 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
492 ms |
41920 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
303 ms |
37968 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
700 ms |
72548 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
431 ms |
49096 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
314 ms |
37792 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
295 ms |
37836 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
315 ms |
38048 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
500 ms |
48576 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
526 ms |
49524 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
644 ms |
60472 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
233 ms |
35920 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
246 ms |
36180 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
381 ms |
39000 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
272 ms |
37864 KB |
200000 token(s): yes count is 129674, no count is 70326 |