#include<bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
using namespace __gnu_pbds;
using namespace std;
using namespace __gnu_cxx;
using namespace std;
const int N = (int)2e5 + 10;
vector < int > g[N];
int pred[N], h[N];
int son[N], used[N];
array < int , 4 > q[N];/// x1 , y1 , x2 , y2
bool ans[N];
vector < int > stac;
vector < pair < int , int > > dots;
vector < int > que[N];
vector < int > P[N], y[N];
void dfs(int v, int H){
stac.pb(v);
used[v] = 1;
h[v] = H;
for(auto &i : que[v]){
int w = q[i][2] - q[i][0] - 1;
if(h[v] < w){
continue;
}
int id = sz(stac)-1-w;
int par = stac[id];
if(dots[par].se <= q[i][3]){
ans[i] = 1;
}
}
for(auto u : g[v]){
assert(!used[u]);
pred[u] = v;
dfs(u, H + 1);
}
stac.pop_back();
}
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int R , C, n , t;
cin >> R >> C >> n;
dots.resize(n);
for(auto &i : dots)
cin >> i.fi >> i.se;
cin >> t;
vector < int > rows;
for(auto &i : dots)
rows.pb(i.fi);
sort(all(rows));
rows.erase(unique(all(rows)), rows.end());
reverse(all(rows));
vector < int > perm(n);
iota(all(perm) , 0);
sort(all(perm) , [&](int x , int y){
if(dots[x].fi == dots[y].fi){
return dots[x].se < dots[y].se;
}
return dots[x].fi > dots[y].fi;
});
int lst = 0;
vector < int > cand, val;
int jj = 0;
for(int r : rows){
vector < int > cur;
while(lst < sz(perm) && dots[perm[lst]].fi == r){
/// add it
y[jj].pb(dots[perm[lst]].se);
P[jj].pb(perm[lst]);
cur.pb(perm[lst]);
int id = lower_bound(all(val) , dots[perm[lst]].se) - val.begin();
if(id != sz(val)){
int par = cand[id];
son[perm[lst]] = 1;
g[par].pb(perm[lst]);
}
lst++;
}
cand.clear(), val.clear();
for(int f : cur){
cand.pb(f);
val.pb(dots[f].se);
}
vector<int>t=val;
sort(all(t));
assert(t==val);
jj++;
}
reverse(all(rows));
/// reversed oder
for(int i = 0 ; i < t; ++i){
int x1 , y1 , x2 , y2;
cin >> x1 >> y1 >> x2 >> y2;
if(x1 > x2 || y1 > y2){
continue;
}
if(x1 == x2){
ans[i] = 1;
continue;
}
q[i] = {x1 , y1 , x2 , y2};
int v;
int id = lower_bound(all(rows), x1) - rows.begin();
if(id == sz(rows)){
continue;
}
if(rows[id] != x1){
continue;
}
// cout << i << "FOUND " << endl;
id = sz(rows) - 1 - id;
int id1 = lower_bound(all(y[id]), y1) - y[id].begin();
if(id1 == sz(y[id])){
continue;
}
// cout << i << " FOUND " << v << endl;
v = P[id][id1];
que[v].pb(i);
}
for(int i = 0 ; i < n; ++i){
if(!son[i]){
assert(!used[i]);
pred[i] = i;
dfs(i , 0);
}
}
for(int i = 0; i < t; ++i){
cout << (ans[i] ? "Yes" : "No") << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
19660 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
16 ms |
19760 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
13 ms |
19636 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
33176 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
129 ms |
33208 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
134 ms |
34532 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
131 ms |
33316 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
302 ms |
46928 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
451 ms |
42268 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
478 ms |
41792 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
394 ms |
42980 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
465 ms |
43188 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
554 ms |
49896 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
19936 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
16 ms |
19868 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
15 ms |
20164 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
14 ms |
19900 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
16 ms |
19980 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
14 ms |
19884 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
446 ms |
59140 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
372 ms |
52892 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
272 ms |
49108 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
409 ms |
76984 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
338 ms |
59228 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
286 ms |
50068 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
296 ms |
49976 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
275 ms |
49128 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
364 ms |
57436 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
392 ms |
58204 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
592 ms |
66828 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
296 ms |
47788 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
238 ms |
47964 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
329 ms |
50924 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
286 ms |
49176 KB |
200000 token(s): yes count is 129674, no count is 70326 |