# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
919607 | andrei_iorgulescu | Trampoline (info1cup20_trampoline) | C++14 | 1018 ms | 44356 KiB |
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;
int r,c,n,q;
int x[200005],y[200005];
map<int,vector<pair<int,int>>>v;
int jump[20][200005];
set<int>st;
int lg[200005];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> r >> c >> n;
for (int i = 1; i <= n; i++)
{
cin >> x[i] >> y[i];
v[x[i]].push_back({y[i],i});
st.insert(x[i]);
}
for (auto it : st)
sort(v[it].begin(),v[it].end());
for (int i = 1; i <= n; i++)
{
int xx = x[i] + 1,yy = y[i];
int st = -1,pas = 1 << 17;
while (pas != 0)
{
if (st + pas < v[xx].size() and v[xx][st + pas].first < yy)
st += pas;
pas /= 2;
}
st++;
if (st == v[xx].size())
jump[0][i] = -1;
else
jump[0][i] = v[xx][st].second;
}
for (int i = 2; i <= n; i++)
lg[i] = 1 + lg[i / 2];
for (int b = 1; b <= lg[n]; b++)
{
for (int i = 1; i <= n; i++)
{
if (jump[b - 1][i] == -1)
jump[b][i] = -1;
else
jump[b][i] = jump[b - 1][jump[b - 1][i]];
}
}
cin >> q;
for (int i = 1; i <= q; i++)
{
int xs,ys,xf,yf;
cin >> xs >> ys >> xf >> yf;
if (xs > xf or ys > yf)
cout << "No\n";
else if (xs == xf)
cout << "Yes\n";
else
{
int xx = xs,yy = ys;
int st = -1,pas = 1 << 17;
//cout << yy << ' ' << v[xx][0].first << '\n';
while (pas != 0)
{
if (st + pas < v[xx].size() and v[xx][st + pas].first < yy)
st += pas;
pas /= 2;
}
st++;
//cout << st << ' ';
if (st == v[xx].size())
cout << "No\n";
else
{
int tr = v[xx][st].second;
//cout << tr << ' ';
for (int b = lg[n]; b >= 0; b--)
{
//cout << jump[b][tr] << ' ';
if (jump[b][tr] != -1 and y[jump[b][tr]] <= yf)
tr = jump[b][tr];
}
if (x[tr] + 1 >= xf)
cout << "Yes\n";
else
cout << "No\n";
}
}
}
return 0;
}
/**
next[i] = care e urmatoarea verde in care as merge din trambulina i
fac binary lifting pe treaba asta
vad in ce trambulina verde urc si daca pe jumpurile aleia ajung la linia xf inainte de yf
**/
Compilation message (stderr)
# | 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... |