#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<ll, ll>
#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define MX(a,b) a = max(a,b)
#define MN(a,b) a = min(a,b)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
#define pb push_back
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do( T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do( T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT
const int maxn = 2e5+5;
int row[maxn], col[maxn];
int nxt[20][maxn];
map<int, vector<pii> > mp; // the vectors store {col, index}
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
bug(1,2);
int R,C; cin>>R>>C;
int n; cin>>n;
REP(i,n) {
int r, c; cin>>r>>c;
mp[r].pb({c, i});
row[i] = r; col[i] = c;
}
nxt[0][n] = n; row[n] = R+1; col[n] = C+1;
for (auto &u : mp) {
sort(ALL(u.s));
}
for (auto &u : mp) {
for (pii p : u.s) {
auto it = lower_bound(ALL(mp[u.f+1]), pii{p.f, -1});
if (it == mp[u.f+1].end()) {
nxt[0][p.s] = n;
}else{
nxt[0][p.s] = it->s;
}
}
}
for (int j = 1; j<20; ++j) {
REP(i,n+1) {
nxt[j][i] = nxt[j-1][nxt[j-1][i]];
}
}
int q; cin>>q;
while (q--) {
ll Rs, Cs, Re, Ce;
cin>>Rs>>Cs>>Re>>Ce;
if (Re < Rs || Ce < Cs) {
bug("bruh");
cout<<"No"<<endl; continue;
}
if (Re == Rs) {
bug("same row...");
cout<<"Yes"<<endl; continue;
}
if (!mp.count(Rs)) {
bug("no available down");
cout<<"No"<<endl; continue;
}
auto it = lower_bound(ALL(mp[Rs]), make_pair(Cs, -1ll));
int who = (it==mp[Rs].end())?(n) : it->s;
if (it != mp[Rs].end())
bug(it->f, it->s);
for (int i = 19; i>=0; --i) {
int ty = nxt[i][who];
if (ty != n && row[ty] < Re) {
who = nxt[i][who];
}
}
if (who!=n && row[who] == Re-1 && col[who] <= Ce) {
cout<<"Yes"<<endl;
}else{
bug("Sorry! Toof ar!");
cout<<"No"<<endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1356 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
4 ms |
1612 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
3 ms |
1228 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
23364 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
88 ms |
25216 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
79 ms |
23492 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
95 ms |
25216 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
238 ms |
22708 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
299 ms |
22016 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
289 ms |
22040 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
464 ms |
23396 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
434 ms |
23404 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
683 ms |
28744 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1024 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
6 ms |
1228 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
9 ms |
2124 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
5 ms |
1228 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
9 ms |
1356 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
5 ms |
1228 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
756 ms |
29940 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
605 ms |
37096 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
291 ms |
33936 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
968 ms |
51904 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
525 ms |
39872 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
332 ms |
34352 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
315 ms |
34428 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
284 ms |
33740 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
701 ms |
40312 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
753 ms |
40972 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
854 ms |
45880 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
261 ms |
33204 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
268 ms |
34120 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
409 ms |
35068 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
238 ms |
33616 KB |
200000 token(s): yes count is 129674, no count is 70326 |