#include<bits/stdc++.h>
using namespace std;
#define x1 sdfds
#define y1 sdfdfds
#define x2 sdffdsds
#define y2 sdfdds
const int MAXN=2e5+6;
struct trampoline
{
int x,y;
bool operator<(trampoline const& other)const
{
return make_pair(x,y)<make_pair(other.x,other.y);
}
};
set<int>xs;
int n,m,k;
vector<trampoline>tr;
map<int,int> newx;
vector<int>xs1;
set<int>ys[MAXN];
vector<int>g[MAXN];
int dp[MAXN][20];
map<pair<int,int>,int> no;
bool vis[MAXN];
int not_root[MAXN];
void dfs(int u,int par)
{
dp[u][0]=par;
vis[u]=1;
for(auto v:g[u])
{
if(vis[v])continue;
dfs(v,u);
}
}
void precompute()
{
for(int j=1;j<20;j++)
{
for(int i=0;i<tr.size();i++)
{
if(dp[i][j-1]==-1)dp[i][j]=-1;
else dp[i][j]=dp[dp[i][j-1]][j-1];
}
}
}
int main()
{
cin>>n>>m>>k;
for(int i=0;i<k;i++)
{
int x,y;
cin>>x>>y;
xs.insert(x);
tr.push_back({x,y});
}
int cnt=0;
for(auto xd:xs)
{
newx[xd]=++cnt;
xs1.push_back(xd);
}
for(int i=0;i<tr.size();i++)
{
ys[newx[tr[i].x]].insert(tr[i].y);
no[{newx[tr[i].x],tr[i].y}]=i;
}
for(int i=0;i<tr.size();i++)
{
if(!newx.count(tr[i].x+1))
{
continue;
}
int x1=newx[tr[i].x+1];
auto xd=ys[x1].lower_bound(tr[i].y);
if(xd==ys[x1].end())continue;
int nxt=no[{x1,(*xd)}];
//cout<<"da\n";
g[nxt].push_back(i);
//cout<<tr[i].x<<" "<<tr[i].y<<" "<<x1<<" "<<(*xd)<<endl;
//cout<<"* "<<nxt<<"->"<<i<<endl;
not_root[i]=1;
}
for(int i=0;i<tr.size();i++)
{
if(vis[i])
{
continue;
}
if(not_root[i])
{
continue;
}
dfs(i,-1);
}
precompute();
/*for(int i=0;i<tr.size();i++)
{
cout<<i<<"->"<<dp[i][0]<<endl;
}
cout<<endl;*/
int q;
cin>>q;
for(int i=0;i<q;i++)
{
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
if(x1==x2)
{
cout<<"Yes\n";
continue;
}
if(!newx.count(x1))
{
cout<<"No\n";
continue;
}
if(!newx.count(x2-1))
{
cout<<"No\n";
continue;
}
int xx=newx[x1];
auto xd=ys[xx].lower_bound(y1);
if(xd==ys[xx].end())
{
cout<<"No\n";
continue;
}
int u=no[{xx,(*xd)}];
for(int j=19;j>=0;j--)
{
if(dp[u][j]==-1)continue;
if(tr[dp[u][j]].x<x2)
{
u=dp[u][j];
}
}
if(tr[u].x!=x2-1)
{
cout<<"No\n";
continue;
}
if(tr[u].y>y2)
{
cout<<"No\n";
continue;
}
cout<<"Yes\n";
continue;
}
return 0;
}
Compilation message
trampoline.cpp: In function 'void precompute()':
trampoline.cpp:41:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<trampoline>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i=0;i<tr.size();i++)
| ~^~~~~~~~~~
trampoline.cpp: In function 'int main()':
trampoline.cpp:64:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<trampoline>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int i=0;i<tr.size();i++)
| ~^~~~~~~~~~
trampoline.cpp:69:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<trampoline>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for(int i=0;i<tr.size();i++)
| ~^~~~~~~~~~
trampoline.cpp:85:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<trampoline>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(int i=0;i<tr.size();i++)
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
16364 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
28 ms |
16748 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
23 ms |
15980 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
832 ms |
60084 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
823 ms |
59996 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
797 ms |
61532 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
871 ms |
60064 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1762 ms |
68520 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
1893 ms |
70220 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
1944 ms |
70232 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Execution timed out |
2089 ms |
70856 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
15852 KB |
expected NO, found YES [16th token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2091 ms |
79348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |