/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define eb emplace_back
#define PI 3.14159265359
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define BIT(x,i) (1&((x)>>(i)))
#define MASK(x) (1LL<<(x))
#define task "tnc"
using namespace std;
typedef long long ll;
const ll INF=1e18;
const int maxn=1e6+5;
const int mod=1e9+7;
const int mo=998244353;
using pi=pair<ll,ll>;
using vi=vector<ll>;
using pii=pair<pair<ll,ll>,ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int r,c;
int n,t;
pair<int,int>z[200005];
pair<int,int>k[200005][19];
map<int,vector<pair<int,int>>>p;
vector<int>q;
signed main()
{
cin.tie(0),cout.tie(0)->sync_with_stdio(0);
cin>>r>>c;
cin>>n;
for(int i=1;i<=n;i++){
cin>>z[i].fi>>z[i].se;
q.pb(z[i].fi);
p[z[i].fi].pb({z[i].se,i});
}
for(auto v:p){
p[v.fi].pb({1e9+5,0});
sort(p[v.fi].begin(),p[v.fi].end());
}
z[0]={1e9+5,0};
for(int i=1;i<=n;i++){
if(p[z[i].fi+1].size()==0)k[i][0]={1e9+5,0};
else{
int dit=lower_bound(p[z[i].fi+1].begin(),p[z[i].fi+1].end(),mp(z[i].se,0))-p[z[i].fi+1].begin();
//cout<<i<<" "<<q[dit].fi<<" "<<q[dit].se<<"\n";
k[i][0]={p[z[i].fi+1][dit].fi,p[z[i].fi+1][dit].se};
}
}
k[0][0]={1e9+5,0};
for(int j=1;j<=18;j++){
for(int i=1;i<=n;i++){
k[i][j]=k[k[i][j-1].se][j-1];
if(k[i][j-1].fi==1e9+5)k[i][j]={1e9+5,0};
}
}
int t;
cin>>t;
while(t--){
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
if(x1==x2 && y1<=y2){
cout<<"Yes\n";
}
else{
int high=x2-x1-1;
if(p[x1].size()==0){
cout<<"No\n";
continue;
}
int d=lower_bound(p[x1].begin(),p[x1].end(),mp(y1,0))-p[x1].begin();
int st=p[x1][d].se;
if(p[x1][d].fi==1e9+5){
cout<<"No\n";
continue;
}
for(int i=18;i>=0;i--){
if((1<<i)&high){
st=k[st][i].se;
}
}
if(z[st].fi<=y2){
cout<<"Yes\n";
}
else{
cout<<"No\n";
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
1804 KB |
expected NO, found YES [7th token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
217 ms |
35564 KB |
expected YES, found NO [12th token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
272 ms |
35440 KB |
expected YES, found NO [4th token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
1248 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
869 ms |
44224 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |