#include<bits/stdc++.h>
using namespace std;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define int long long int
#define endl '\n'
#define N 200100
#define M 30
#define big 2147483647
#define bigg 9223372036854775807
#define pb push_back
#define p push
#define ins insert
#define f first
#define s second
int lca[N][M];
vector<int> adj[N], comprez;
vector<pair<int,int>> ikinci;
int gittik[N];
void dfs(int x,int a,int b){
if(gittik[x])return ;
gittik[x]=1;
lca[x][0]=x;
pair<int,int> pa={a+1,b};
int yeni=(lower_bound(ikinci.begin(),ikinci.end(),pa)-ikinci.begin());
if(yeni!=ikinci.size()&&ikinci[yeni].f==a+1&&gittik[yeni]==0){
lca[x][0]=yeni;
dfs(yeni,a+1,ikinci[yeni].s);
return;
}
}
void doldur(){
for(int i=1;i<M;i++){
for(int j=0;j<ikinci.size();j++){
lca[j][i]=lca[lca[j][i-1]][i-1];
}
}
}
int qua(int x,int y,int a,int b){
a--;
pair<int,int> pa={x,y};
int node=lower_bound(ikinci.begin(),ikinci.end(),pa)-ikinci.begin();
if(node==ikinci.size()||ikinci[node].f!=x) return 0;
int fark=a-x;
for(int i=0;i<M;i++){
if((fark&(1<<i))){
node=lca[node][i];
}
}
x=ikinci[node].f, y=ikinci[node].s;
if(x==a&&y<=b)return 1;
return 0;
}
signed main(){
lalala;
int r,c,n;cin>>r>>c>>n;
vector<pair<int,int>> v;
vector<int> yedek;
for(int i=0;i<n;i++){
int a,b;cin>>a>>b;
v.pb({b,a});
yedek.pb(a);
ikinci.pb({a,b});
}
sort(v.begin(),v.end());
sort(yedek.begin(),yedek.end());
sort(ikinci.begin(),ikinci.end());
comprez.pb(yedek[0]);
for(int i=1;i<n;i++){
if(yedek[i]!=yedek[i-1])comprez.pb(yedek[i]);
}
for(auto u:v){
int yer=u.s;
int kim=lower_bound(comprez.begin(),comprez.end(),yer)-comprez.begin();
adj[kim].pb(u.f);
}
for(int i=0;i<(int)ikinci.size();i++){
if(gittik[i])continue;
dfs(i,ikinci[i].f,ikinci[i].s);
}
doldur();
int q;cin>>q;
while(q--){
int x,y,a,b;cin>>x>>y>>a>>b;
if(x>a||y>b){
cout<<"No"<<endl;
continue;
}
if(x==a){
cout<<"Yes"<<endl;
continue;
}
int ok=qua(x,y,a,b);
if(ok)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
Compilation message
trampoline.cpp: In function 'void dfs(long long int, long long int, long long int)':
trampoline.cpp:28:9: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | if(yeni!=ikinci.size()&&ikinci[yeni].f==a+1&&gittik[yeni]==0){
| ~~~~^~~~~~~~~~~~~~~
trampoline.cpp: In function 'void doldur()':
trampoline.cpp:36:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int j=0;j<ikinci.size();j++){
| ~^~~~~~~~~~~~~~
trampoline.cpp: In function 'long long int qua(long long int, long long int, long long int, long long int)':
trampoline.cpp:46:9: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | if(node==ikinci.size()||ikinci[node].f!=x) return 0;
| ~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
7760 KB |
expected YES, found NO [5th token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
133 ms |
66068 KB |
expected YES, found NO [3rd token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
195 ms |
76804 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
233 ms |
77072 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
196 ms |
76056 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
225 ms |
76108 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
209 ms |
76056 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
220 ms |
77844 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
7000 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
268 ms |
77856 KB |
expected YES, found NO [3rd token] |
2 |
Halted |
0 ms |
0 KB |
- |