#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
const int mn = 2e5 + 5;
vector<int> cmp, row[mn];
int nxt[mn][21], x[mn], y[mn];
bool found (int targ) {
auto it = lower_bound(all(cmp), targ);
return it != cmp.end() && *it == targ;
}
int getID (int targ) {
return lower_bound(all(cmp), targ) - cmp.begin() + 1;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int r, c, n; cin >> r >> c >> n;
for (int i = 1; i <= n; i++) {
cin >> x[i] >> y[i];
cmp.push_back(x[i]);
}
sort(all(cmp)), filter(cmp);
for (int i = 1; i <= n; i++)
row[getID(x[i])].push_back(i);
for (int i = 1; i <= n; i++)
sort(all(row[i]), [&] (int a, int b) { return y[a] < y[b]; });
for (int i = 1; i <= n; i++) {
if (!found(x[i] + 1)) continue;
int cur = getID(x[i] + 1);
auto it = lower_bound(all(row[cur]), y[i],
[&] (int a, int b) { return y[a] < b; });
if (it != row[cur].end()) nxt[i][0] = *it;
}
for (int s = 1; s < 21; s++)
for (int i = 1; i <= n; i++)
nxt[i][s] = nxt[nxt[i][s - 1]][s - 1];
int q; cin >> q;
while (q--) {
int stx, sty, enx, eny; cin >> stx >> sty >> enx >> eny;
if (stx > enx) {
cout << "No\n";
continue;
}
else if (stx == enx) {
cout << (sty <= eny ? "Yes" : "No") << "\n";
continue;
}
else {
int curRow = getID(stx);
auto it = lower_bound(all(row[curRow]), sty,
[&] (int a, int b) { return y[a] < b; });
if (it == row[curRow].end()) {
cout << "No\n";
continue;
}
int cur = *it;
for (int step = enx - stx - 1, i = 0; step; step >>= 1, i++)
if (step & 1) cur = nxt[cur][i];
cout << (cur && y[cur] <= eny ? "Yes" : "No") << "\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
10832 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
8 ms |
10832 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
5 ms |
8712 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
25284 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
103 ms |
25320 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
99 ms |
24848 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
106 ms |
25292 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
173 ms |
25648 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
203 ms |
25796 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
187 ms |
25728 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
202 ms |
25796 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
208 ms |
25796 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
228 ms |
26820 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8528 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
6 ms |
8528 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
9 ms |
8784 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
7 ms |
8896 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
7 ms |
8528 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
6 ms |
8528 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
244 ms |
27076 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
229 ms |
26088 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
198 ms |
25540 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
298 ms |
42436 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
216 ms |
38920 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
204 ms |
37628 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
215 ms |
37596 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
216 ms |
37316 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
240 ms |
38360 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
243 ms |
38508 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
270 ms |
40388 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
184 ms |
37572 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
189 ms |
37576 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
239 ms |
37572 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
202 ms |
37800 KB |
200000 token(s): yes count is 129674, no count is 70326 |