#include <bits/stdc++.h>
using namespace std;
/* Problem: Trampoline
* Complexity: O(NlogN + TlogN)
* Score: 100
*/
const int Nmax = 2e5 + 5, lg = 20, lim = 1e9;
int n, m, p;
int father[lg+2][Nmax], Next[Nmax];
pair<int,int> a[Nmax];
int nr_yes, nr_no, cVal;
void answer_yes(int x)
{
cout << "Yes\n";
}
void answer_no(int x)
{
cout << "No\n";
}
void Read()
{
assert( cin >> n >> m >> p );
assert( n <= lim && m <= lim && p <= 200000);
int i;
for(i=1; i<=p; ++i)
cin >> a[i].first >> a[i].second;
sort(a+1, a+p+1);
}
int BinarySearch(pair<int,int> w)
{
int l = 1, r = p, mid;
while(l <= r)
{
mid = (l + r) / 2;
if(a[mid] < w) l = mid + 1;
else r = mid - 1;
}
return l;
}
void ComputeNext()
{
int i;
for(i=1; i<=p; ++i)
{
int id = BinarySearch({ a[i].first + 1, a[i].second });
if(id > p || a[id].first != a[i].first + 1)
Next[i] = 0;
else Next[i] = id;
}
}
void ComputeAncestors()
{
int i, j;
for(i=1; i<=p; ++i)
father[0][i] = Next[i];
for(i=1; i<=lg; ++i)
for(j=1; j<=p; ++j)
father[i][j] = father[i-1][father[i-1][j]];
}
int FindMyAncestor(int node, int up)
{
int i;
for(i=0; i<=lg; ++i)
if(up & (1<<i))
{
node = father[i][node];
if(!node) return 0;
}
return node;
}
void SolveQueries()
{
int q;
assert( cin >> q );
assert ( q <= 200000 );
int i;
for(i=1; i<=q; ++i)
{
int X1, Y1, X2, Y2;
assert( cin >> X1 >> Y1 >> X2 >> Y2 );
assert( 1 <= X1 && 1 <= X2 && 1 <= Y1 && 1 <= Y2 && X1 <= lim && X2 <= lim && Y1 <= lim && Y2 <= lim);
if(make_pair(X1, Y1) > make_pair(X2, Y2))
{
answer_no(i);
continue;
}
if(X1 == X2)
{
answer_yes(i);
continue;
}
int id = BinarySearch({X1, Y1});
if(id > p || a[id].first != X1)
{
answer_no(i);
continue;
}
int w = FindMyAncestor(id, X2 - X1 - 1);
if(w == 0)
{
answer_no(i);
continue;
}
if(a[w].second <= Y2)
answer_yes(i);
else answer_no(i);
}
}
int main()
{
cin.sync_with_stdio(false); cin.tie(0);
Read();
ComputeNext();
ComputeAncestors();
SolveQueries();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1272 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
9 ms |
1400 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
7 ms |
1144 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
19192 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
90 ms |
19192 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
88 ms |
19308 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
90 ms |
19192 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
251 ms |
19832 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
264 ms |
19960 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
263 ms |
19832 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
278 ms |
19832 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
271 ms |
19832 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
268 ms |
19828 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1016 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
11 ms |
888 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
13 ms |
1016 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
11 ms |
1020 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
11 ms |
888 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
12 ms |
1144 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
399 ms |
19976 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
381 ms |
19832 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
292 ms |
19832 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
397 ms |
19960 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
324 ms |
19944 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
270 ms |
19832 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
293 ms |
19948 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
287 ms |
19832 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
398 ms |
19924 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
390 ms |
19960 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
402 ms |
20088 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
256 ms |
19832 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
272 ms |
19960 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
331 ms |
19952 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
267 ms |
19960 KB |
200000 token(s): yes count is 129674, no count is 70326 |