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>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9
// #define fisier 1
using namespace std;
typedef long long ll;
int r, c, n, q;
pair<int, int> p[200002];
int lvl[200002];
int anc[20][200002];
int cb(pair<int, int> x)
{
int st = 1;
int dr = n;
int ans = 0;
while(st <= dr)
{
int mid = (st + dr) / 2;
if(p[mid] >= x)
ans = mid, dr = mid - 1;
else
st = mid + 1;
}
return ans;
}
int kthanc(int a, int stp)
{
for(int i = 19; i >= 0; --i)
if(stp >= (1<<i))
a = anc[i][a], stp -= (1<<i);
return a;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> r >> c >> n;
for(int i = 1; i <= n; ++i)
cin >> p[i].fi >> p[i].se;
sort(p + 1, p + n + 1);
for(int i = n; i >= 1; --i)
{
int nxttr = cb({p[i].fi + 1, p[i].se});
if(p[nxttr].fi == p[i].fi + 1)
{
lvl[i] = lvl[nxttr] + 1;
anc[0][i] = nxttr;
for(int j = 1; j <= 19; ++j)
anc[j][i] = anc[j-1][anc[j-1][i]];
}
}
cin >> q;
for(; q; --q)
{
int xa, ya, xb, yb;
cin >> xa >> ya >> xb >> yb;
if(xa > xb || ya > yb)
{
cout << "No\n";
continue;
}
if(xa == xb)
{
cout << "Yes\n";
continue;
}
int nxttr = cb({xa, ya});
if(p[nxttr].fi > xa || p[nxttr].se > yb)
{
cout << "No\n";
continue;
}
if(lvl[nxttr] < xb - xa - 1)
{
cout << "No\n";
continue;
}
int poz = kthanc(nxttr, xb - xa - 1);
if(p[poz].fi <= xb && p[poz].se <= yb)
{
cout << "Yes\n";
continue;
}
cout << "No\n";
continue;
}
return 0;
}
# | 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... |