#include <bits/stdc++.h>
using namespace std;
#define ld long double
// #define int long long
#define endl "\n"
const int N = 3e5,K = 20;
int r,c,n,q;
map<int,vector<int>> green;
vector<vector<int>> idx;
vector<int> row;
vector<int> sparse[N + 1][K + 1];
int query(int r1,int c1,int r2) {
r1--;
r2--;
int len = r2 - r1;
if(r1 == r2) {
auto it = lower_bound(idx[r1].begin(),idx[r1].end(),c1);
return (*it);
}
auto it = lower_bound(idx[r1].begin(),idx[r1].end(),c1);
if(it == idx[r1].end()) return INT_MAX;
int pp = it - idx[r1].begin();
int res = c1;
for(int j = K;j >= 0;j--) {
int tmp = (len >> j) % 2;
if(tmp == 0) continue;
int nxt = sparse[r1][j][pp];
r1 += (1<<j);
res = max(res,nxt);
it = lower_bound(idx[r1].begin(),idx[r1].end(),nxt);
if(it == idx[r1].end()) {
return INT_MAX;
}
pp = it - idx[r1].begin();
}
return res;
}
map<int,int> uy;
signed main() {
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
cin>>r>>c>>n;
for(int i = 0;i < n;i++) {
int x,y;
cin>>x>>y;
green[x].push_back(y);
}
for(auto u : green) {
u.second.push_back(INT_MAX);
sort(u.second.begin(),u.second.end());
idx.push_back(u.second);
row.push_back(u.first);
}
for(int i = 0;i < idx.size();i++) {
for(int j = 0;j <= K;j++) {
sparse[i][j].assign(idx[i].size(),0);
}
}
for(int i = 0;i < idx.size();i++) {
uy[row[i]] = i + 1;
for(int j = 0;j < idx[i].size();j++) {
if(i == (int)idx.size() - 1 || row[i] + 1 != row[i + 1]) {
sparse[i][0][j] = INT_MAX;
} else {
auto it = lower_bound(idx[i + 1].begin(),idx[i + 1].end(),idx[i][j]);
if(it == idx[i + 1].end()) {
sparse[i][0][j] = INT_MAX;
} else {
sparse[i][0][j] = (*it);
}
}
}
}
for(int j = 1;j <= K;j++) {
for(int i = 0;i + (1<<j) <= (int)idx.size();i++) {
for(int pp = 0;pp < idx[i].size();pp++) {
int fi = sparse[i][j - 1][pp];
auto it = lower_bound(idx[i + (1<<(j - 1))].begin(),idx[i + (1<<(j - 1))].end(),fi);
if(row[i + (1<<(j - 1)) - 1] + 1 != row[i + (1<<(j - 1))]) {
sparse[i][j][pp] = INT_MAX;
} else {
int pos = it - idx[i + (1<<(j - 1))].begin();
sparse[i][j][pp] = sparse[i + (1<<(j - 1))][j - 1][pos];
}
}
}
}
int q;
cin>>q;
while(q--) {
int r1,c1,r2,c2;
cin>>r1>>c1>>r2>>c2;
if(r1 > r2 || c1 > c2) {
cout<<"NO"<<endl;
continue;
}
if(r1 == r2) {
cout<<"YES"<<endl;
continue;
}
r1 = uy[r1];
if(r1 == 0) {
cout<<"NO"<<endl;
continue;
}
int mn = INT_MAX;
if(uy[r2] != 0) {
mn = min(mn,query(r1,c1,uy[r2]));
}
if(uy[r2 - 1] != 0) {
mn = min(mn,query(r1,c1,uy[r2 - 1]));
}
if(mn > c2) {
cout<<"NO"<<endl;
} else {
cout<<"YES"<<endl;
}
}
return 0;
}
Compilation message
trampoline.cpp: In function 'int main()':
trampoline.cpp:79:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int i = 0;i < idx.size();i++) {
| ~~^~~~~~~~~~~~
trampoline.cpp:85:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(int i = 0;i < idx.size();i++) {
| ~~^~~~~~~~~~~~
trampoline.cpp:88:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(int j = 0;j < idx[i].size();j++) {
| ~~^~~~~~~~~~~~~~~
trampoline.cpp:104:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | for(int pp = 0;pp < idx[i].size();pp++) {
| ~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
149180 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
80 ms |
149364 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
86 ms |
149020 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
204 ms |
168196 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
183 ms |
168184 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
222 ms |
166900 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
232 ms |
168224 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
385 ms |
166932 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
317 ms |
166940 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
345 ms |
167180 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
365 ms |
168564 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
372 ms |
168444 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
698 ms |
209248 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
148792 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
80 ms |
148716 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
84 ms |
152700 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
79 ms |
148732 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
81 ms |
149752 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
87 ms |
148680 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
889 ms |
219576 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
632 ms |
178648 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
345 ms |
167256 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
1237 ms |
323764 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
699 ms |
221804 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
351 ms |
167028 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
342 ms |
166984 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
315 ms |
167092 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
765 ms |
209356 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
839 ms |
207816 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
1030 ms |
265568 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
270 ms |
166964 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
277 ms |
166936 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
436 ms |
168008 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
276 ms |
167028 KB |
200000 token(s): yes count is 129674, no count is 70326 |