This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include<fstream>
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
//ifstream fin("FEEDING.INP");
//ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ll mxn = 3e5 + 5, base = 972663749;
const ll mod = 911382323, mxv = 1e9 + 1, inf = 2e9;
int n, t, r, c;
map<int, set<int>>point;
map<pair<int, int>, int>id;
map<int, pair<int, int>>toid;
int mark = 0;
int up[mxn + 1][18], a[mxn + 1], b[mxn + 1];
int x1, y11, x2, y2;
void solve(){
auto st = point[x1].lower_bound(y11);
if(st == point[x1].end()){
cout << "No" << "\n";
return;
}
int stid = id[make_pair(x1, *st)];
int k = x2 - x1 - 1;
for(int i = 0; i < 18; i++){
if(k & (1 << i)){
stid = up[stid][i];
}
}
if(stid == 0){
cout << "No" << "\n";
return;
}
auto [enx, eny] = toid[stid];
assert(enx == x2 - 1);
cout << ((eny <= y2) ? "Yes" : "No") << "\n";
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> r >> c >> n;
for(int i = 1; i <= n; i++){
cin >> a[i] >> b[i];
point[a[i]].insert(b[i]);
id[{a[i], b[i]}] = ++mark;
toid[mark] = make_pair(a[i], b[i]);
}
for(auto i: point){
set<int>cand = i.second;
for(auto j: cand){
auto it = point[i.fi + 1].lower_bound(j);
if(it != point[i.fi + 1].end()){
up[id[make_pair(i.fi, j)]][0] = id[make_pair(i.fi + 1, *it)];
}
}
}
for(int i = 1; i < 18; i++){
for(int j = 1; j <= n; j++){
up[j][i] = up[up[j][i - 1]][i - 1];
}
}
cin >> t;
while(t--){
cin >> x1 >> y11 >> x2 >> y2;
if(x1 > x2 || y11 > y2){
cout << "No" << "\n";
}else if(x1 == x2){
cout << "Yes" << "\n";
}else{
solve();
}
}
return(0);
}
Compilation message (stderr)
trampoline.cpp: In function 'void solve()':
trampoline.cpp:46:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
46 | auto [enx, eny] = toid[stid];
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |