#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
int p[200005][18];
vector<int> V[200005];
void dfs(int x,int par){
p[x][0]=par;
for(int k=1;k < 18;++k){
int half_parent = p[x][k-1];
if(half_parent == -1)continue;
p[x][k] = p[half_parent][k-1];
}
for(auto v:V[x]){
if(v==par)continue;
dfs(v,x);
}
}
int query_parent(int x,int h){
for (int k=0;k<18;++k){
if( ((1<<k) & h) == 0)continue; // We only do this if the bit in h is on
x = p[x][k]; // travel up to parent
if (x == -1)return -1; // h-th parent does not exist
}
return x;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int r, c, n; cin >> r >> c >> n;
set<pair<pair<int, int>, int> > green;
set<pair<pair<int, int>, int> , greater<pair<pair<int, int>, int> > > greenn;
map<int, pair<int, int> > m;
for(int i=0; i<n; i++){
int a, b; cin >> a >> b;
green.insert(make_pair(make_pair(a, b), i));
greenn.insert(make_pair(make_pair(a, b), i));
m[i]= make_pair(a, b);
}
set<pair<pair<int, int>, int> > ::iterator it;
for(it= green.begin(); it!=green.end(); it++){
int a= it->first.first;
int b= it->first.second;
int c= it->second;
set<pair<pair<int, int>, int> > ::iterator itt;
for(itt= green.lower_bound(make_pair(make_pair(a+1, b), -1)); itt!=green.end(); itt++){
int d= itt->first.first;
//int e= itt->first.second;
int f= itt->second;
if(d!=a+1){break;}
V[c].push_back(f);
}
}
dfs(green.begin()->first.first, -1);
int q; cin >> q;
for(int i=0; i<q; i++){
int a, b, c, d; cin >> a >> b >> c >> d;
int e= c-a;
if(e==0){
if(b<d){cout << "Yes" << endl; continue;}
else{cout << "No" << endl; continue;}
}
set<pair<pair<int, int>, int> > ::iterator itit= greenn.lower_bound(make_pair(make_pair(c-1, d), 300000));
int f= itit->first.first;
//cout << "f " << f << endl;
if(f!=c-1){cout << "No" << endl; continue;}
if(e==1){
if(itit->first.second<=b){cout << "Yes" << endl; continue;}
else{cout << "No" << endl; continue;}
}
int g= query_parent(itit->second, e-1);
//cout << "g " << g << endl;
if(g==-1){cout << "No" << endl; continue;}
pair<int, int> temp= m[g];
//cout << "temp.second " << temp.second << endl;
if(temp.second>=b){cout << "Yes" << endl; continue;}
else{cout << "No" << endl; continue;}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
40 ms |
9352 KB |
expected NO, found YES [2nd token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2048 ms |
138328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2083 ms |
158484 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
29 ms |
22860 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
508 ms |
100768 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |