#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
ll an[200005][20];
ll depth[200005];
vector<vll>adj;
void build(ll s,ll p){
an[s][0] = p;
f(i,1,20){
an[s][i] = an[an[s][i-1]][i-1];
}
for(auto x:adj[s]){
if(x != p){
depth[x] = depth[s] + 1;
build(x,s);
}
}
}
ll kth(ll x,ll k){
ll ans = x;
if(depth[x] <= k){
return 0;
}
ll pos = 0;
while(k > 0){
if(k % 2){
ans = an[ans][pos];
}
pos++;
k /= 2;
}
return ans;
}
int main(void){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll r,c;
cin>>r>>c;
map<ll,ll>mp;
set<ll>ex;
ll n;
cin>>n;
ll a[n+1],b[n+1];
adj.assign(200005,vll());
f(i,0,n){
cin>>a[i]>>b[i];
ex.insert(a[i]);
}
ll pos = 0;
for(auto x:ex){
mp[x] = pos;
pos++;
}
set<ll> exo[(ll)ex.size() + 5];
ii sim[200005];
map<ii,ll>M;
pos = 1;
f(i,0,n){
exo[mp[a[i]]].insert(b[i]);
sim[pos] = ii(a[i],b[i]);
M[ii(a[i],b[i])] = pos;
pos++;
}
ll p = 0;
for(auto x:ex){
for(auto y:exo[p]){
if(!ex.count(x+1)){
adj[0].pb(M[ii(x,y)]);
adj[M[ii(x,y)]].pb(0);
}
auto it = exo[p+1].lower_bound(y);
if(it == exo[p+1].end()){
adj[0].pb(M[ii(x,y)]);
adj[M[ii(x,y)]].pb(0);
}
else{
adj[M[ii(x+1,(*it))]].pb(M[ii(x,y)]);
adj[M[ii(x,y)]].pb(M[ii(x+1,(*it))]);
}
}
p++;
}
build(0,0);
ll t;
cin>>t;
while(t--){
ll xa,ya,xb,yb;
cin>>xa>>ya>>xb>>yb;
bool ok = 1;
if(xa > xb || ya > yb){
ok = 0;
}
auto it = exo[mp[xa]].lower_bound(ya);
if(xa != xb){
if(!ex.count(xa) || it == exo[mp[xa]].end()){
ok = 0;
}
else{
ll v = kth(M[ii(xa,(*it))],xb - xa - 1);
if(v == 0 || sim[v].S > yb){
ok = 0;
}
}
}
if(ok){
cout<<"Yes\n";
}
else{
cout<<"No\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
10956 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
18 ms |
11368 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
13 ms |
10444 KB |
197 token(s): yes count is 25, no count is 172 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
439 ms |
73928 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
475 ms |
73844 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
483 ms |
72876 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
469 ms |
74028 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
675 ms |
75080 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
675 ms |
76208 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
730 ms |
74192 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
814 ms |
74436 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
856 ms |
74336 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
1098 ms |
87684 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
9804 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
15 ms |
9804 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
22 ms |
10880 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
13 ms |
9740 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
16 ms |
10092 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
13 ms |
9804 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1366 ms |
90216 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
1115 ms |
89772 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
784 ms |
86024 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
1580 ms |
125376 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
1032 ms |
100184 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
747 ms |
88084 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
744 ms |
87932 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
806 ms |
86036 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
1250 ms |
99300 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
1282 ms |
99080 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
1586 ms |
112592 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
708 ms |
87036 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
730 ms |
86776 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
895 ms |
86056 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
737 ms |
85848 KB |
200000 token(s): yes count is 129674, no count is 70326 |