/*
#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,1e9+5};
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].se==0)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].se<=y2){
cout<<"Yes\n";
}
else{
cout<<"No\n";
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1876 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
6 ms |
2004 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
5 ms |
1544 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
207 ms |
35564 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
228 ms |
35516 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
193 ms |
34760 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
211 ms |
35428 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
240 ms |
35576 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
279 ms |
35536 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
273 ms |
35320 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
437 ms |
35904 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
437 ms |
35920 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
649 ms |
42880 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1236 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
7 ms |
1252 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
10 ms |
2004 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
9 ms |
1236 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
9 ms |
1416 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
8 ms |
1256 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
852 ms |
44452 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
569 ms |
38208 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
345 ms |
35204 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
1152 ms |
55068 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
660 ms |
42508 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
327 ms |
35812 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
345 ms |
35780 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
372 ms |
35360 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
922 ms |
42740 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
935 ms |
43184 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
1012 ms |
50660 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
290 ms |
35348 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
279 ms |
35332 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
481 ms |
35768 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
292 ms |
35540 KB |
200000 token(s): yes count is 129674, no count is 70326 |