#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("Ofast,unroll-loops")
#include "bits/stdc++.h"
using namespace std;
//~ #ifndef ONLINE_JUDGE
//~ #include "debug.h"
//~ #else
//~ #define debug(...)
//~ #define debugArr(...)
//~ #endif
#define int long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define pb push_back
template<class T, class U> inline bool chmin(T& a, const U& b) { if (a > b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmax(T& a, const U& b) { if (a < b) { a = b; return true; } return false; }
const int inf = 1e9;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;
void solve() {
int r,c,n;
cin >> r >> c >> n;
if(r <= 2500 && c <= 2500) {
int a[n],b[n];
vector<pair<int,int>> v;
for(int i = 0;i < n;i++) {
cin >> a[i] >> b[i];
v.pb({a[i],b[i]});
}
sort(all(v));
int q;
cin >> q;
while(q--) {
int xs,ys,xf,yf;
cin >> xs >> ys >> xf >> yf;
bool check = 0;
for(int i = 0;i < n;i++) {
if(xs == xf && yf >= ys) {
check = 1;
break;
}
if(v[i].ff == xs && v[i].ss >= ys) {
xs++;
ys = v[i].ss;
}
}
if(xs == xf && yf >= ys) {
check = 1;
}
if(check) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return;
}
int a[n],b[n];
vector<pair<int,int>> v;
map<int,vector<pair<int,int>>> mp;
set<int> st;
for(int i = 0;i < n;i++) {
cin >> a[i] >> b[i];
v.pb({a[i],b[i]});
st.insert(a[i]);
}
sort(all(v));
reverse(all(v));
int id = 0;
vector<vector<pair<int,int>>> up(n,vector<pair<int,int>> (20,{-1,-1}));
vector<int> pr(n,-1);
for(auto [i,j] : v) {
mp[i].pb({j,id++});
}
for(auto i : st) sort(all(mp[i]));
id = 0;
int last = -1;
for(auto [i,j] : v) {
if(mp.find(i + 1) == mp.end()) {
last = i;
id++;
continue;
}
int lst = pr[id - 1] - 1;
if(pr[id - 1] == -1 || last != i) lst = mp[i + 1].size() - 1;
while(lst >= 0 && mp[i + 1][lst].ff >= j) {
lst--;
}
lst++;
pr[id] = lst;
if(lst == (int)mp[i + 1].size()) continue;
up[id][0] = {mp[i + 1][lst]};
for(int k = 1;k < 20;k++) {
if(up[id][k - 1].ss == -1) break;
up[id][k] = {up[up[id][k - 1].ss][k - 1]};
//~ if(last == i) {
//~ if(up[id - 1][k].ff < up[id][k].ff) {
//~ up[id - 1][k] = up[id][k];
//~ }
//~ }
}
id++;
last = i;
}
auto get = [&](int a,int k) -> int {
int val = inf;
for(int i = 0;i < 20;i++) {
if(k >> i & 1) {
val = up[a][i].ff;
a = up[a][i].ss;
if(a == -1) {
return -1;
}
}
}
return val;
};
int q;
cin >> q;
while(q--) {
int xs,ys,xf,yf;
cin >> xs >> ys >> xf >> yf;
if(xs == xf && ys <= yf) {
cout << "Yes\n";
continue;
} else if(xs == xf) {
cout << "No\n";
continue;
}
int ans = -1,l = 0,r = mp[xs].size() - 1;
while(l <= r) {
int mid = l + (r - l) / 2;
if(mp[xs][mid].ff >= ys) {
r = mid - 1;
ans = mid;
} else {
l = mid + 1;
}
}
if(ans == -1 || xf < xs) {
cout << "No\n";
} else {
int x = 0;
if(xf - xs == 1) {
x = mp[xs][ans].ff;
} else {
x = get(mp[xs][ans].ss,xf - xs - 1);
}
if(x <= yf && x != -1) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int t = 1;
//~ cin >> t;
while(t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
848 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
4 ms |
848 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
3 ms |
592 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
365 ms |
9672 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
362 ms |
10628 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
413 ms |
9672 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
407 ms |
11208 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
246 ms |
84640 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
246 ms |
85436 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
259 ms |
83644 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
323 ms |
84840 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
319 ms |
84960 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
435 ms |
93360 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2384 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
7 ms |
2384 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
9 ms |
3152 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
7 ms |
2384 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
9 ms |
2640 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
7 ms |
2384 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
699 ms |
95192 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
538 ms |
87472 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
348 ms |
83584 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
911 ms |
111568 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
481 ms |
93612 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
327 ms |
85432 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
297 ms |
85432 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
271 ms |
83640 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
581 ms |
93624 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
602 ms |
93492 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
652 ms |
102408 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
235 ms |
85432 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
274 ms |
84860 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
461 ms |
84740 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
256 ms |
85848 KB |
200000 token(s): yes count is 129674, no count is 70326 |