This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)4e5 + 10;
const int LOG = 19;
int ii[N], jj[N];
int nx[LOG][N];
vector<pii> imp;
int fin(pii xx){
return lower_bound(imp.begin(), imp.end(), xx) - imp.begin();
}
int main(){
fastIO;
int r,c,t;
cin >> r >> c >> t;
set<pii> aq;
for(int id = 0; id < t; id ++ ){
cin >> ii[id] >> jj[id];
aq.insert(mp(ii[id], jj[id]));
imp.push_back(mp(ii[id], jj[id]));
imp.push_back(mp(ii[id] + 1, jj[id]));
}
sort(imp.begin(), imp.end());
imp.resize(unique(imp.begin(), imp.end()) - imp.begin());
int m = imp.size();
int ni = -1;
for(int i = m - 1; i >= 0; i -- ){
if(i == m - 1 || imp[i].fi != imp[i + 1].fi)
ni = -1;
if(aq.count(imp[i])){
ni = fin(mp(imp[i].fi + 1, imp[i].se));
}
nx[0][i] = ni;
}
for(int i = 1; i < LOG; i++ ){
for(int j = 0 ;j < m ; j ++ ){
if(nx[i-1][j] != -1){
nx[i][j]=nx[i-1][nx[i-1][j]];
}
}
}
int q;
cin >> q;
int i1, j1, i2, j2;
int st;
for(int id = 0; id < q; id ++ ){
cin >> i1 >> j1 >> i2 >> j2;
if(i1 > i2 || j1 > j2){
cout << "No\n";
}
else{
if(i1 == i2){
cout << "Yes\n";
}
else{
st = lower_bound(imp.begin(), imp.end(), mp(i1, j1)) - imp.begin();
if(st == imp.size() || imp[st].fi != i1){
cout << "No\n";
}
else{
for(int q = 0; q < LOG; q ++ ){
if(((i2-i1)&(1<<q))){
if(st != -1) st = nx[q][st];
}
}
if(st != -1 && imp[st].fi == i2 && imp[st].se <= j2){
cout << "Yes\n";
}
else{
cout << "No\n";
}
}
}
}
}
return 0;
}
Compilation message (stderr)
trampoline.cpp: In function 'int main()':
trampoline.cpp:70:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | if(st == imp.size() || imp[st].fi != i1){
| ~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |