#include <bits/stdc++.h>
#define m_p make_pair
#define f first
#define s second
#define vec vector
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pw(x) (1LL<<x)
#define sz(x) (int)x.size()
#define fast_ioi ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long double ld;
typedef pair<long long,long long> pll;
template <class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
template <class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
auto rng=bind(uniform_int_distribution<int>(1,20),mt19937(time(0)));
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
const int N=2e5+1;
const int lg=log2(N);
int go[N][lg];
//void mg(int a,int b){
// if(a==-1) return -1;
//
//}
signed main(){
fast_ioi;
int n,m,k;
cin>>n>>m>>k;
vec<pii>ar(k);
map<int,set<pii>>st;
// vec<vec<int>>up(n,vec<int>())
for(auto &z : ar)
cin>>z.f>>z.s;
for(int i=0;i<n;i++) st[ar[i].f].insert({ar[i].s,i});
const int inf=1e9;
for(int i=0;i<k;i++){
auto it=st[ar[i].f+1].lower_bound(m_p(ar[i].s,-inf));
if(it==st[ar[i].f+1].end()) go[i][0]=-1;
else go[i][0]=it->s;
}
for(int j=1;j<lg;j++){
for(int i=0;i<k;i++){
go[i][j]=(go[i][j-1]==-1?-1:go[go[i][j-1]][j-1]);
// debug()<<imie(i)imie(j)imie(go[i][j])imie(go[i][j-1]);
}
}
auto get=[&](int i,int dx){
if(dx>n) return -1;
// debug()<<imie(i)imie(dx);
for(int j=0;j<lg;j++){
if(pw(j)&dx){
if(i==-1) i=-1;
else i=go[i][j];
}
}
return i;
};
int q;
cin>>q;
while(q--){
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
if(x1==x2 && y1<=y2){
cout<<"Yes\n";
continue;
}
if(y1>y2 || x1>x2){
cout<<"No\n";
continue;
}
// debug()<<imie(x1)imie(x2)imie(y1)imie(y2);
auto it=st[x1].lower_bound(m_p(y1,-inf));
// debug()<<imie(*it);
if(it==st[x1].end()){
cout<<"No\n";
continue;
}
// debug()<<imie(*it);
int j=it->s;
j=get(j,x2-x1-1);
if(j==-1 || ar[j].s>y2){
cout<<"No\n";
}
else{
cout<<"Yes\n";
}
}
return 0;
}
/*
6 1
5447 7526 7703 8705 18716 19718 19895
1582 7087 7911 14379 14703 14703 19265 19265 19589 26057 32386
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
972 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
106 ms |
17504 KB |
expected YES, found NO [3rd token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
134 ms |
26800 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2072 ms |
383256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
205 ms |
41976 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |