/*
#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][18];
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());
}
sort(z+1,z+1+n);
sort(q.begin(),q.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{
vector<pair<int,int>>q=p[z[i].fi+1];
int dit=lower_bound(q.begin(),q.end(),mp(z[i].se,0))-q.begin();
//cout<<i<<" "<<q[dit].fi<<" "<<q[dit].se<<"\n";
k[i][0]={q[dit].fi,q[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;
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 |
5 ms |
1748 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
162 ms |
34004 KB |
expected YES, found NO [3rd token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2088 ms |
10868 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
1108 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
655 ms |
42648 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |