#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 (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;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
1356 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
87 ms |
23288 KB |
expected YES, found NO [3rd token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
236 ms |
22724 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
256 ms |
23888 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
256 ms |
23776 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
345 ms |
25144 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
345 ms |
25172 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
498 ms |
30668 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
972 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
592 ms |
29796 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |