#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#define YMAX 1e9 + 1
#define NMAX 200000 //doua sute cincizeci de mii
#define LOG_LOWERBOUND 30 //e pt 1e9
using namespace std;
ifstream fin ("test.in");
ofstream fout ("test.out");
int R, C, N, T;
pair <int, int> s[NMAX + 1];
int t[LOG_LOWERBOUND + 1][NMAX + 1];
int log2(int VAL){ ///LOWERBOUND
int lo = -1;
int hi = 29 + 1;
int rsp;
while(hi - lo > 1){
int mid = lo + (hi - lo) / 2;
if( (1 << mid) <= VAL ){
rsp = mid;
lo = mid;
}
else {
hi = mid;
}
}
return rsp;
}
int cautareBinara(int x, int y){
/*
Imi returneaza, din lista de trambuline verzi, numarul celei de pe linia x, cu lowerboundul ei = y
daca nu exista niciunul pe linia x, returneaza 0
*/
int lo = 0;
int hi = N + 1;
int ans = 0;
while(hi - lo > 1){
int mid = lo + (hi - lo) / 2;
if(s[mid].first > x){
hi = mid;
}
else if(s[mid].first < x){
lo = mid;
}
else if(s[mid].second < y){
lo = mid;
}
else {
ans = mid;
hi = mid;
}
}
return ans;
}
int stramos(int node, int nr){
if(nr == 0){
return s[node].second;
}
for(int i = log2(nr); i >= 0; i--){
if( (1 << i) <= nr ){
node = t[i][node];
nr -= (1 << i);
}
}
///daca node ajunge sa fie 0, inseamna ca nu exista al nr-lea stramos al lui node
///dar la mine trebuie sa existe ca sa zic 'Yes', ca altfel inseamna ca nu am destule trambuline pe drum
///adica inseamna ca nu am trambuline de la (xs, xf) destule
///si atunci vreau sa returnez ceva care sa ma faca sa afisez 'No', adica returnez un 'y' f mare, pentru ca eu urmeaza sa il compar cu yf
if(node == 0){
return YMAX + 1;
}
return s[node].second; ///returneaza 'y'-ul celui de-al 'nr'-ulea stramos al lui 'node'
}
int main()
{
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
cin >> R >> C >> N; ///globale
for(int i = 1; i <= N; i++){
cin >> s[i].first >> s[i].second;
}
sort(s + 1, s + N + 1);
for(int i = 1; i <= N; i++){
int aux = cautareBinara(s[i].first + 1, s[i].second);
t[0][i] = aux;
}
for(int i = 1; i <= log2(N); i++){
for(int j = 1; j <= N; j++){
t[i][j] = t[i - 1][ t[i - 1][j] ];
}
}
cin >> T; ///global
for(int Q = 1; Q <= T; Q++){
int xs, ys, xf, yf;
cin >> xs >> ys >> xf >> yf;
if(xf == xs){ ///caz special ca altfel am niste valori cu -1 si nu are sens
if(ys <= yf){
cout << "Yes\n";
}
else {
cout << "No\n";
}
}
else if(xs > xf || ys > yf){
cout << "No\n";
}
else {
int st = cautareBinara(xs, ys); ///caut cel mai din stanga valid de pe linia 'xs'
if(st == 0){
cout << "No\n";
}
else if( stramos(st, xf - 1 - xs) <= yf ){ ///verific al 'xf - 1 - xs'-lea stramos al acestuia si verific daca e mai mic ca 'yf'
cout << "Yes\n";
}
else {
cout << "No\n";
}
}
}
return 0;
}
Compilation message
trampoline.cpp: In function 'int log2(int)':
trampoline.cpp:36:12: warning: 'rsp' may be used uninitialized in this function [-Wmaybe-uninitialized]
36 | return rsp;
| ^~~
trampoline.cpp: In function 'int stramos(int, int)':
trampoline.cpp:77:18: warning: 'rsp' may be used uninitialized in this function [-Wmaybe-uninitialized]
77 | node = t[i][node];
| ~~~~~^~~~~~~~~~~~
trampoline.cpp: In function 'int main()':
trampoline.cpp:111:22: warning: 'rsp' may be used uninitialized in this function [-Wmaybe-uninitialized]
111 | for(int i = 1; i <= log2(N); i++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
844 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
4 ms |
972 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
4 ms |
716 KB |
197 token(s): yes count is 25, no count is 172 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
15908 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
74 ms |
15964 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
61 ms |
15972 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
66 ms |
15968 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
170 ms |
16600 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
186 ms |
16628 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
167 ms |
16568 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
185 ms |
16596 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
178 ms |
16620 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
177 ms |
16672 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
716 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
7 ms |
716 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
6 ms |
716 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
7 ms |
716 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
8 ms |
716 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
5 ms |
716 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
230 ms |
16708 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
237 ms |
16684 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
249 ms |
16804 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
257 ms |
16724 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
195 ms |
16740 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
186 ms |
16708 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
181 ms |
16712 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
244 ms |
16660 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
238 ms |
16708 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
296 ms |
16680 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
274 ms |
16812 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
188 ms |
16592 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
168 ms |
16740 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
208 ms |
16708 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
173 ms |
16664 KB |
200000 token(s): yes count is 129674, no count is 70326 |