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>
using namespace std;
map<int, vector<int>>lin;
#define YES cout << "Yes\n"
#define NO cout << "No\n"
int n;
int nxt[200005][19]; /// nxt[i] - urmatoarea trambulina dupa a[i]
struct trambulina
{
int x, y;
bool operator < (const trambulina aux) const
{
if (x == aux.x)
return y < aux.y;
return x < aux.x;
}
};
trambulina a[200005];
int after_jump (int x, int y)
{
int l=1, r=n;
int sol = n + 1;
while (l <= r)
{
int mid = (l + r) / 2;
if (a[mid].x < x)
l = mid + 1 ;
else if (a[mid].x > x)
r = mid - 1;
else
{
if (a[mid].y >= y)
sol = mid, r = mid-1;
else
l = mid + 1;
}
}
return sol;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int r, c;
cin >> r >> c >> n;
for (int i=1; i<=n; i++)
cin >> a[i].x >> a[i].y;
sort(a+1, a+n+1);
a[++n] = {r+1, c+1};
/**
nxt[i] - urmatoarea trambulina
**/
for (int i=1; i<=n; i++)
{
nxt[i][0] = after_jump(a[i].x+1, a[i].y);
}
for (int j=1; (1 << j) < n; j++)
{
for (int i=1; i<n; i++)
{
nxt[i][j] = nxt[nxt[i][j-1]][j-1];
}
}
int t;
cin >> t;
while (t--)
{
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 > x2 || y1 > y2 || x2 - x1 > n)
{
NO;
continue;
}
else if (x1 == x2)
YES;
else
{
int d = x2 - x1 - 1;
int pos = after_jump(x1, y1);
if (a[pos].x != x1)
{
NO;
continue;
}
for (int b=0; b<18; b++)
{
if (d & (1 << b))
{
pos = nxt[pos][b];
}
}
if (pos >= n)
{
NO;
continue;
}
if (a[pos].x + 1 == x2 && a[pos].y <= y2)
YES;
else
NO;
}
}
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... |