Submission #514672

#TimeUsernameProblemLanguageResultExecution timeMemory
514672bebecanvasTrampoline (info1cup20_trampoline)C++14
0 / 100
2086 ms165792 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' int p[200005][18]; vector<int> V[200005]; void dfs(int x,int par){ p[x][0]=par; for(int k=1;k < 18;++k){ int half_parent = p[x][k-1]; if(half_parent == -1)continue; p[x][k] = p[half_parent][k-1]; } for(auto v:V[x]){ if(v==par)continue; dfs(v,x); } } int query_parent(int x,int h){ for (int k=0;k<18;++k){ if( ((1<<k) & h) == 0)continue; // We only do this if the bit in h is on x = p[x][k]; // travel up to parent if (x == -1)return -1; // h-th parent does not exist } return x; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); int r, c, n; cin >> r >> c >> n; set<pair<pair<int, int>, int> > green; set<pair<pair<int, int>, int> , greater<pair<pair<int, int>, int> > > greenn; map<int, pair<int, int> > m; for(int i=0; i<n; i++){ int a, b; cin >> a >> b; green.insert(make_pair(make_pair(a, b), i)); greenn.insert(make_pair(make_pair(a, b), i)); m[i]= make_pair(a, b); } set<pair<pair<int, int>, int> > ::iterator it; for(it= green.begin(); it!=green.end(); it++){ int a= it->first.first; int b= it->first.second; int c= it->second; set<pair<pair<int, int>, int> > ::iterator itt; for(itt= green.lower_bound(make_pair(make_pair(a+1, b), -1)); itt!=green.end(); itt++){ int d= itt->first.first; //int e= itt->first.second; int f= itt->second; if(d!=a+1){break;} V[c].push_back(f); } } dfs(green.begin()->first.first, -1); int q; cin >> q; for(int i=0; i<q; i++){ int a, b, c, d; cin >> a >> b >> c >> d; int e= c-a; if(e==0){ if(b<d){cout << "Yes" << endl; continue;} else{cout << "No" << endl; continue;} } set<pair<pair<int, int>, int> > ::iterator itit= greenn.lower_bound(make_pair(make_pair(c-1, d), 300000)); int f= itit->first.first; //cout << "f " << f << endl; if(f!=c-1){cout << "No" << endl; continue;} if(e==1){ if(itit->first.second>=b){cout << "Yes" << endl; continue;} else{cout << "No" << endl; continue;} } int g= query_parent(itit->second, e-1); //cout << "g " << g << endl; if(g==-1){cout << "No" << endl; continue;} pair<int, int> temp= m[g]; //cout << "temp.second " << temp.second << endl; if(temp.second>=b){cout << "Yes" << endl; continue;} else{cout << "No" << endl; continue;} } }
#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...