#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][18], 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 < 18; 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];
if (cur == 0) cout << "No\n";
else cout << (y[cur] <= eny ? "Yes" : "No") << "\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8272 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
6 ms |
10576 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
5 ms |
8440 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
24836 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
104 ms |
24836 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
104 ms |
24260 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
100 ms |
24824 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
183 ms |
35096 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
199 ms |
35192 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
194 ms |
35012 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
206 ms |
35268 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
206 ms |
35280 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
224 ms |
36040 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 |
7 ms |
8528 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
6 ms |
8772 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
6 ms |
8528 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 |
8696 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
245 ms |
32196 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
241 ms |
35524 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Incorrect |
219 ms |
35084 KB |
expected NO, found YES [70th token] |
4 |
Halted |
0 ms |
0 KB |
- |