#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define OYY LLONG_MAX
#define mod 998244353
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define FOR for(int i=1;i<=n;i++)
#define mid (start+end)/2
#define lim 200005
#define fi first
#define se second
vector<pair<int,int>> v[lim];
int x[lim],y[lim];
set<int> st;
map<int,int> mp;
int timer,l;
int up[lim][25];
int32_t main(){
faster
int r,c,n;cin>>r>>c>>n;
l=ceil(log2(n));
FOR{
cin>>x[i]>>y[i];
st.insert(x[i]);
}
for(auto a:st){
mp[a]=++timer;
}
FOR{
v[mp[x[i]]].push_back({y[i],i});
}
for(int i=1;i<=timer;i++){
sort(v[i].begin(),v[i].end());
}
FOR{
if(mp.find(x[i]+1)==mp.end())continue;
if(v[mp[x[i]+1]].back().fi<y[i])continue;
int tut=lower_bound(v[mp[x[i]+1]].begin(),v[mp[x[i]+1]].end(),make_pair(y[i],0ll))-v[mp[x[i]+1]].begin();
up[i][0]=v[mp[x[i]+1]][tut].se;
}
for(int i=1;i<=l;i++){
for(int j=1;j<=n;j++){
up[j][i]=up[up[j][i-1]][i-1];
}
}
int q;cin>>q;
while(q--){
int x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2;
if(y1>y2){
cout<<"No"<<'\n';
continue;
}
if(x1==x2){
cout<<"Yes"<<'\n';
continue;
}
if(x1>x2){
cout<<"No"<<'\n';
continue;
}
if(mp.find(x1)==mp.end()){
cout<<"No"<<'\n';
continue;
}
if(v[mp[x1]].back().fi<y1){
cout<<"No"<<'\n';
continue;
}
int node=lower_bound(v[mp[x1]].begin(),v[mp[x1]].end(),make_pair(y1,0ll))-v[mp[x1]].begin();
node=v[mp[x1]][node].se;
for(int i=l;i>=0;i--){
if(up[node][i] && x[up[node][i]]<x2){
node=up[node][i];
}
}
if(x[node]==x2-1 && y[node]<=y2)cout<<"Yes"<<'\n';
else cout<<"No"<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
12636 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
5 ms |
12892 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
4 ms |
12636 KB |
197 token(s): yes count is 25, no count is 172 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
138 ms |
53028 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
141 ms |
54768 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
98 ms |
53328 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
137 ms |
54864 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
164 ms |
52420 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
179 ms |
51828 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
178 ms |
51988 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
310 ms |
53072 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
286 ms |
53168 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
515 ms |
60500 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
12636 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
6 ms |
12636 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
8 ms |
11868 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
5 ms |
12892 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
8 ms |
13148 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
5 ms |
12892 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
567 ms |
62160 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
424 ms |
55388 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
196 ms |
51928 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
740 ms |
87892 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
447 ms |
71844 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
186 ms |
64204 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
188 ms |
64200 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
173 ms |
63372 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
539 ms |
72268 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
546 ms |
72276 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
626 ms |
79656 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
152 ms |
63264 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
152 ms |
63932 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
271 ms |
64848 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
161 ms |
63400 KB |
200000 token(s): yes count is 129674, no count is 70326 |