#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() - 1; i++) {
sort(row[i].begin(),row[i].end());
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
6656 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
302 ms |
37864 KB |
expected YES, found NO [3rd token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
522 ms |
38248 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
534 ms |
38456 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
535 ms |
38508 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
586 ms |
38252 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
584 ms |
38404 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
666 ms |
39528 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
6016 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
705 ms |
39660 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |