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;
#define sz(x) (int) (x).size()
#define all(x) (x).begin(), (x).end()
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define tern(cond, a, b) (cond ? a : b)
typedef long long lint;
typedef pair<lint,lint> ii;
ii arr[200005];
map<int, vector<ii> > M;
int p[20][200005];
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int R, C, n; cin >> R >> C >> n;
for(int i = 1;i <= n;i++){
cin >> arr[i].first >> arr[i].second;
M[arr[i].first].push_back(ii(arr[i].second,i));
}
for(auto &p : M){
sort(all(p.second));
}
for(auto &P : M){
vector<ii> &A = P.second;
if(M.find(P.first+1) == M.end()) continue;
vector<ii> &B = M[P.first+1];
for(ii a : A){
auto it = lower_bound(all(B), ii(a.first, -1));
if(it == B.end()) continue;
p[0][a.second] = it->second;
}
}
for(int k = 1;k <= 19;k++){
for(int i = 1;i <= n;i++){
p[k][i] = p[k-1][p[k-1][i]];
}
}
int Q; cin >> Q;
while(Q--){
int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2;
if(r1 > r2){
cout << "No\n";
continue;
}
if(r1 == r2){
if(c1 <= c2) cout << "Yes\n";
else cout << "No\n";
continue;
}
if(M.find(r1) == M.end()){
cout << "No\n";
continue;
}
auto it = lower_bound(all(M[r1]), ii(c1, -1));
if(it == M[r1].end()){
cout << "No\n";
continue;
}
int u = it->second;
for(int k = 0;k <= 19;k++){
if((r2-r1-1)&(1<<k)){
u = p[k][u];
}
}
if(u == 0){
cout << "No\n";
continue;
}
if(arr[u].second <= c2) cout << "Yes\n";
else cout << "No\n";
}
}
# | 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... |