#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define pp pair<pii, int>
const int N = 2e5+10;
const int K = 20;
vector<int> G[N];
pii p[N];
set<pii> s[N];
int r, c, n, indeg[N], up[N][K+1];
void dfs(int v, int p) {
up[v][0]=p;
for (int i=1; i<=K; ++i) up[v][i]=up[up[v][i-1]][i-1];
for (auto u : G[v]) {
if (u == p) continue;
dfs(u, v);
}
}
int fv(int i, int x) {
for (int k=K; k>=0; --k) {
int idx=up[i][k];
if (p[idx].first < x) i=up[i][k];
}
return i;
}
void solve() {
cin>>r>>c>>n;
for (int i=1; i<=n; ++i) {
int a, b; cin>>a>>b;
p[i]={a, b};
s[a].insert({b, i});
}
for (int i=1; i<=n; ++i) {
int a=p[i].first, b=p[i].second;
auto ptr=s[a+1].lower_bound({b, -1});
if (ptr == s[a+1].end()) continue;
G[a].push_back(i);
++indeg[i];
}
for (int i=1; i<=n; ++i) {
if (indeg[i] == 0) dfs(i, i);
}
int q; cin>>q;
for (int i=1; i<=q; ++i) {
int is, js, ie, je;
cin>>is>>js>>ie>>je;
if (js > je) cout<<"No\n";
else if (is == ie) cout<<"Yes\n";
else {
auto ptr=s[is].lower_bound({js, -1});
if (ptr == s[is].end()) {
cout<<"No\n";
continue;
}
int f=fv(ptr->second, ie);
if (p[f].first == ie-1 && p[f].second <= je) cout<<"Yes\n";
else cout<<"No\n";
}
}
for (int i=1; i<=n; ++i) s[i].clear(), G[i].clear();
}
int main() {
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
15656 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
288 ms |
45900 KB |
expected YES, found NO [3rd token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
19 ms |
29012 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
22 ms |
29008 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
21 ms |
29020 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |