Submission #342734

#TimeUsernameProblemLanguageResultExecution timeMemory
342734ogibogi2004Trampoline (info1cup20_trampoline)C++14
100 / 100
1587 ms89308 KiB
#include<bits/stdc++.h> using namespace std; #define x1 sdfds #define y1 sdfdfds #define x2 sdffdsds #define y2 sdfdds #define ll int const ll MAXN=2e5+6; struct trampoline { ll x,y; bool operator<(trampoline const& other)const { return make_pair(x,y)<make_pair(other.x,other.y); } }; set<ll>xs; ll n,m,k; vector<trampoline>tr; unordered_map<ll,ll> newx; vector<ll>xs1; set<ll>ys[MAXN]; vector<ll>g[MAXN]; ll dp[MAXN][18]; map<pair<ll,ll>,ll> no; bool vis[MAXN]; ll not_root[MAXN]; void dfs(ll u,ll par) { dp[u][0]=par; vis[u]=1; for(auto v:g[u]) { if(vis[v])continue; dfs(v,u); } } void precompute() { for(ll j=1;j<18;j++) { for(ll 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() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n>>m>>k; for(ll i=0;i<k;++i) { ll x,y; cin>>x>>y; xs.insert(x); tr.push_back({x,y}); } ll cnt=0; for(auto xd:xs) { newx[xd]=++cnt; xs1.push_back(xd); } for(ll 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(ll i=0;i<tr.size();++i) { if(!newx.count(tr[i].x+1)) { continue; } ll x1=newx[tr[i].x+1]; auto xd=ys[x1].lower_bound(tr[i].y); if(xd==ys[x1].end())continue; ll 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(ll i=0;i<tr.size();++i) { if(vis[i]) { continue; } if(not_root[i]) { continue; } dfs(i,-1); } precompute(); /*for(ll i=0;i<tr.size();i++) { cout<<i<<"->"<<dp[i][0]<<endl; } cout<<endl;*/ ll q; cin>>q; for(ll i=0;i<q;++i) { ll x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2; if(y2<y1) { cout<<"No\n"; continue; } if(x2<x1) { cout<<"No\n"; continue; } if(x1==x2) { cout<<"Yes\n"; continue; } if(!newx.count(x1)) { cout<<"No\n"; continue; } if(!newx.count(x2-1)) { cout<<"No\n"; continue; } ll xx=newx[x1]; auto xd=ys[xx].lower_bound(y1); if(xd==ys[xx].end()) { cout<<"No\n"; continue; } ll u=no[{xx,(*xd)}]; /*if(tr[u].x<x1||tr[u].y<y1) { cout<<"No\n"; continue; }*/ for(int j=17;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 (stderr)

trampoline.cpp: In function 'void precompute()':
trampoline.cpp:42:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<trampoline>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   for(ll i=0;i<tr.size();i++)
      |              ~^~~~~~~~~~
trampoline.cpp: In function 'int main()':
trampoline.cpp:68:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<trampoline>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |  for(ll i=0;i<tr.size();++i)
      |             ~^~~~~~~~~~
trampoline.cpp:73:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<trampoline>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |  for(ll i=0;i<tr.size();++i)
      |             ~^~~~~~~~~~
trampoline.cpp:89:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<trampoline>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |  for(ll i=0;i<tr.size();++i)
      |             ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...