#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 600100
#define M 400100
#define offf 2530
#define big 2147483647
#define bigg 9223372036854775807
#define pb push_back
#define p push
#define ins insert
#define f first
#define s second
tuple<int,int,int> bfs[M];
vector<int> adj[N], comprez;
vector<pair<int,int>> ikinci;
int gittik[M];
bool arr[offf][offf],green[offf][offf];
void dfs(int x,int a,int b){
if(x==-1)return;
if(gittik[x])return ;
gittik[x]=1;
pair<int,int> pa={a+1,b};
int yeni=(upper_bound(ikinci.begin(),ikinci.end(),pa)-ikinci.begin())-1;
if(ikinci[yeni].f==a+1&&ikinci[yeni].s==b&&gittik[yeni]==0){
bfs[x]={yeni,a+1,b};
dfs(yeni,a+1,b);
return;
}
int kim=(lower_bound(comprez.begin(),comprez.end(),a)-comprez.begin());
int yer=(lower_bound(adj[kim].begin(),adj[kim].end(),b)-adj[kim].begin());
if(yer!=(int)adj[kim].size()){
pa={a,adj[kim][yer]};
yeni=(upper_bound(ikinci.begin(),ikinci.end(),pa)-ikinci.begin())-1;
bfs[x]={yeni,a,adj[kim][yer]};
dfs(yeni,a,adj[kim][yer]);
return;
}
bfs[x]={-1,-1,-1};
}
int defese(int x,int a,int b,int s,int e){
if(a>s||b>e)return 0;
if(a==s){
return 1;
}
int aa,bb,cc;tie(aa,bb,cc)=bfs[x];
if(a==-1)return 0;
return defese(aa,bb,cc,s,e);
}
void qua(){
int x,y,a,b;cin>>x>>y>>a>>b;
if(x==a){
if(y<=b)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return;
}
if(x>a||y>b){
cout<<"No"<<endl;
return;
}
int kim=(lower_bound(comprez.begin(),comprez.end(),x)-comprez.begin());
if(kim==(int)comprez.size()||comprez[kim]!=x){
cout<<"No"<<endl;
return;
}
int yer=(lower_bound(adj[kim].begin(),adj[kim].end(),y)-adj[kim].begin());
if(yer==(int)adj[kim].size()){
cout<<"No"<<endl;
return;
}
pair<int,int> pa={x,adj[kim][yer]};
int yeni=(upper_bound(ikinci.begin(),ikinci.end(),pa)-ikinci.begin())-1;
int ok=defese(yeni,x,adj[kim][yer],a,b);
if(ok)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
inline bool ancakama(int x,int y,int a,int b,int r,int c){
queue<pair<int,int>> q;
q.p({x,y});
if(x>a)return 0;
if(y>b)return 0;
if(x==a)return 1;
while((int)q.size()){
x=q.front().f,y=q.front().s;
q.pop();
if(arr[x][y])continue;
arr[x][y]=1;
if(x==a&&y<=b)return 1;
if(y>b)continue;
if(x>a)continue;
if(x!=r&&arr[x+1][y]==0&&green[x][y]){
q.p({x+1,y});
continue;
}
if(y!=c&&arr[x][y+1]==0){
q.p({x,y+1});
}
}
return 0;
}
void yaaap(vector<pair<int,int>> v, int n,int q,int r,int c){
for(auto u:v){
green[u.s][u.f]=1;
}
while(q--){
memset(arr,0,sizeof(arr));
int x,y,a,b;cin>>x>>y>>a>>b;
int ok=ancakama(x,y,a,b,r,c);
if(ok)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
void solve(){
int r,c,n;cin>>r>>c>>n;
vector<pair<int,int>> v;
ikinci.clear();
comprez.clear();
vector<int> yedek;
for(int i=0;i<n;i++){
int a,b;cin>>a>>b;
v.pb({b,a});
yedek.pb(a);yedek.pb(b);
yedek.pb(a+1);
ikinci.pb({a,b});
ikinci.pb({a+1,b});
}
int q;cin>>q;
if(q<=4000&&r<=offf-10&&c<=offf-10){
yaaap(v,n,q,r,c);
return;
}
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*3;i++){
if(yedek[i]!=yedek[i-1])comprez.pb(yedek[i]);
if(i<=n*2+5){
gittik[i]=0;
}
adj[i].clear();
}
adj[0].clear();
gittik[0]=0;
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);
}
while(q--){
qua();
}
}
signed main(){
lalala;
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
22016 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
35 ms |
21740 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
39 ms |
21848 KB |
197 token(s): yes count is 25, no count is 172 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
594 ms |
36916 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
604 ms |
37016 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
611 ms |
31984 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
672 ms |
36900 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
256 ms |
41368 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
281 ms |
42392 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
277 ms |
41876 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
327 ms |
42544 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
301 ms |
42488 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
314 ms |
55784 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
15196 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
12 ms |
15196 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
12 ms |
15256 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
12 ms |
15196 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
23 ms |
15620 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
12 ms |
15196 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2047 ms |
50332 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |