제출 #1136331

#제출 시각아이디문제언어결과실행 시간메모리
1136331bpptidpTrampoline (info1cup20_trampoline)C++20
42 / 100
691 ms142184 KiB
#include<bits/stdc++.h> using namespace std; using ll=long long; int R,C,n,t; map<array<int,2>,int>hsh; map<int,array<int,2>>dehsh; vector<array<int,2>>zel,st,en; unordered_map<int,set<int>>rw; map<array<int,2>,bool>ok; map<int,int>comp; const int N=2e4+7; vector<int>g[N]; bitset<N>msk[N]; vector<int>cur; int vis[N]; void dfs(int u){ cur.push_back(u); msk[u]=0; msk[u][u]=1; vis[u]=1; for(int v:g[u]){ if(!vis[v])dfs(v); msk[u]|=msk[v]; } } bool bad(array<int,2>a,array<int,2>b){ int x1=a[0],y1=a[1]; int x2=b[0],y2=b[1]; if(x1>x2)return 1; if(y1>y2)return 1; return 0; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>R>>C>>n; for(int i=0,x,y;i<n;++i){ cin>>x>>y; zel.push_back({x,y}); } cin>>t; for(int i=0,x,y;i<t;++i){ cin>>x>>y; st.push_back({x,y}); cin>>x>>y; en.push_back({x,y}); } set<array<int,2>>ss; for(auto&x:zel)ss.insert(x); for(auto&x:st)ss.insert(x); for(auto&x:en)ss.insert(x); int cc=0; for(auto&x:ss){ hsh[x]=++cc; dehsh[cc]=x; } for(auto&[x,y]:st) rw[x].insert(y); for(auto&[x,y]:en) rw[x].insert(y); for(auto&[x,y]:zel) rw[x].insert(y); for(auto&[x,s]:rw){ int pr=-1; for(auto&y:s){ int cur=hsh[{x,y}]; if(pr!=-1)g[pr].push_back(cur); pr=cur; } } //for(auto&[x,y]:hsh) // cout<<x[0]<<' '<<x[1]<<':'<<' '<<y<<endl; //cout<<endl; for(auto&[x,y]:zel){ auto it=rw[x+1].lower_bound(y); if(it==rw[x+1].end())continue; g[hsh[{x,y}]].push_back(hsh[{x+1,*it}]); } int c2=1; for(int i=1;i<=cc;++i){ if(!vis[i]){ cur.clear(); dfs(i); for(auto&x:cur)comp[x]=c2; ++c2; } } //for(int i=0;i<N;++i){ // if(g[i].size()){ // for(int j:g[i]) // cout<<i<<' '<<j<<endl; // } //} //cout<<endl; for(int i=0;i<t;++i){ int fi=hsh[st[i]]; int se=hsh[en[i]]; //cout<<fi<<' '<<tin[fi]<<' '<<se<<' '<<tin[se]<<' '<<comp[fi]<<' '<<comp[se]<<endl; ok[{fi,se}]=msk[fi][se]; //ok[{fi,se}]&=(comp[fi]==comp[se]); } for(int i=0;i<t;++i){ //if(bad(st[i],en[i]))cout<<"No\n"; /*else*/ cout<<(ok[{hsh[st[i]],hsh[en[i]]}]?"Yes\n":"No\n"); } }
#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...