This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |