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>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7, N = 2e5 + 7;
map<int, V<pi>> mp;
int st[N][20];
signed main()
{
IO_OP;
memset(st, -1, sizeof st);
int r, c, n;
cin >> r >> c >> n;
V<array<int, 3>> v(n);
for(int i = 0; i < n; i++)
cin >> v[i][0] >> v[i][1], v[i][2] = i;
sort(ALL(v));
vi yyy(n);
for(auto p:v) {
yyy[p[2]] = p[1];
mp[p[0]].EB(p[1], p[2]);
}
for(auto& tt:mp) {
int row = tt.F;
for(pi p:tt.S) {
int col = p.F, id = p.S;
if(mp.count(row + 1) == 0) continue;
auto it = lower_bound(ALL(mp[row+1]), MP(col, -INF));
if(it != mp[row+1].end()) {
int idd = it -> S;
// id -> idd
st[id][0] = idd;
}
}
}
for(int j = 1; j < 20; j++) {
for(int i = 0; i < n; i++)
if(st[i][j - 1] != -1) {
st[i][j] = st[st[i][j - 1]][j - 1];
}
}
int t;
cin >> t;
while(t--) {
int x, y, xx, yy;
cin >> x >> y >> xx >> yy;
if(xx < x || yy < y) {
cout << "No" << endl;
continue;
}
if(x == xx) {
cout << "Yes" << endl;
continue;
}
xx--;
auto it = lower_bound(ALL(mp[x]), MP(y, -INF));
auto itt = upper_bound(ALL(mp[xx]), MP(yy, INF));
if(it != mp[x].end() && itt != mp[xx].begin()) {
itt--;
int u = it -> S, v = itt -> S;
int step = xx - x;
for(int j = 0; j < 20; j++) {
if(u == -1) break;
if(step >> j & 1) {
u = st[u][j];
}
}
if(u != -1 && yyy[u] <= yyy[v]) cout << "Yes" << endl;
else cout << "No" << endl;
} else {
cout << "No" << endl;
}
}
}
# | 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... |