#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
const int maxn = 2e5 + 5;
const int LOG = 21;
int n,m,t;
map<pair<int,int>,int> mp;
int X[maxn], Y[maxn];
vector<int> xord;
vector<int> row[maxn];
int par[LOG+1][maxn];
bool solve(int x1, int y1, int x2, int y2) {
if (x1>x2) return false;
if (y1>y2) return false;
if (x1==x2) return true;
int xi = std::lower_bound(xord.begin(),xord.end(),x1)-xord.begin();
if (xi==(int)xord.size() || xord[xi]!=x1) {
return false;
}
int yi = std::lower_bound(row[xi].begin(),row[xi].end(),y1)-row[xi].begin();
if (yi==(int)row[xi].size()) {
return false;
}
int at = mp[{x1, row[xi][yi]}];
int dx = x2-x1-1;
for (int i=LOG-1; i>=0; i--) {
if (dx>>i&1) {
at = par[i][at];
}
}
if (at == 0) return false;
return Y[at] <= y2;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>m>>t;
for (int i=1; i<=t; i++) {
cin>>X[i]>>Y[i];
mp[{X[i],Y[i]}] = i;
xord.push_back(X[i]);
}
sort(xord.begin(),xord.end());
xord.erase(unique(xord.begin(),xord.end()),xord.end());
for (int i=1; i<=t; i++) {
int x = lower_bound(xord.begin(),xord.end(),X[i])-xord.begin();
row[x].push_back(Y[i]);
}
for (int i=0; i<(int)xord.size(); i++) {
sort(row[i].begin(),row[i].end());
}
for (int i=0; i<(int)xord.size() - 1; i++) {
if (xord[i]+1 == xord[i+1]) {
for (int y: row[i]) {
int atId = mp[{xord[i],y}];
int yto = std::lower_bound(row[i+1].begin(),row[i+1].end(),y)-row[i+1].begin();
if (yto < (int)row[i+1].size()) {
int toId = mp[{xord[i]+1,row[i+1][yto]}];
par[0][atId] = toId;
}
}
}
}
for (int j=1; j<LOG; j++) {
for (int i=1; i<=t; i++) {
par[j][i] = par[j-1][par[j-1][i]];
}
}
int q;
cin>>q;
while (q--) {
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
cout<<(solve(x1,y1,x2,y2) ? "Yes\n" : "No\n");
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
6656 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
13 ms |
6912 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
10 ms |
6388 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
303 ms |
37936 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
305 ms |
39656 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
291 ms |
39016 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
297 ms |
39664 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
516 ms |
38352 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
536 ms |
38380 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
547 ms |
38376 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
600 ms |
38380 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
587 ms |
38252 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
641 ms |
39504 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
6016 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
12 ms |
6272 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
12 ms |
6400 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
12 ms |
6272 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
13 ms |
6272 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
12 ms |
6272 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
829 ms |
39776 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
771 ms |
50524 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
564 ms |
50024 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
878 ms |
55016 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
689 ms |
51568 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
628 ms |
50152 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
612 ms |
50280 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
570 ms |
50256 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
788 ms |
51048 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
814 ms |
51096 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
875 ms |
53100 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
514 ms |
50284 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
556 ms |
50284 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
667 ms |
50280 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
539 ms |
50408 KB |
200000 token(s): yes count is 129674, no count is 70326 |