# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1138270 | AbdullahIshfaq | Rainforest Jumps (APIO21_jumps) | C++20 | Compilation error | 0 ms | 0 KiB |
#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
const int lg = 20;
void init(int n, std::vector<int> height){
height.insert(height.begin(), 1e9);
height.insert(height.end(), 1e9);
n += 2;
vector<vector<int>>(n, vector<int>(lg)), left, right, mx;
stack<int> que;
for(int i = 0; i < n; i++){
while (!que.empty() and height[que.top()] <= height[i]){
que.pop();
}
left[i][0] = que.empty() ? i : que.top();
que.push(i);
}
while (!que.empty()){
que.pop();
}
for(int i = n - 1; i >= 0; --i){
while (!que.empty() and height[que.top()] <= height[i]){
que.pop();
}
right[i][0] = que.empty() ? i : que.top();
que.push(i);
}
for(int i = 0; i < n; i++){
if(height[left[i][0]] > height[right[i][0]]){
mx[i][0] = left[i][0];
}
else{
mx[i][0] = right[i][0];
}
}
for(int j = 1; j < lg; j++){
for(int i = 0; i < n; i++){
left[i][j] = left[left[i][j - 1]][j - 1];
right[i][j] = right[right[i][j - 1]][j - 1];
mx[i][j] = mx[mx[i][j - 1]][j - 1];
}
}
}
int minimum_jumps(int a, int b, int c, int d){
a++;
b++;
c++;
d++;
if(b == c - 1){
if(right[b][0] <= d){
return 1;
}
return -1;
}
int mid = l;
for(int j = lg - 1; j >= 0; --j){
if(right[l][j] <= r){
l = right[l][j];
}
}
if(height[b] > height[mid]){
if(right[b][0] <= d){
return 1;
}
return -1;
}
int s = b;
for(int j = lg - 1; j >= 0; --j){
if(a <= left[s][j] and height[left[s][j]] < height[mid]){
s = left[s][j];
}
}
int jmp = 0;
if(a <= left[s][0]){
if(right[left[s][0]][0] <= d){
return 1;
}
}
else{
for(int j = lg - 1; j >= 0; --j){
if(height[mx[s][j]] <= height[mid]){
jmp |= (1 << j);
s = mx[s][j];
}
}
if(s == mid){
return right[s][0] <= d ? jmp + 1 : -1;
}
if(0 < left[s][0] and right[left[s][0]][0] <= d){
return jmp + 2;
}
}
for(int j = lg - 1; j >= 0; --j){
if(right[s][j] < c){
jmp += (1 << j);
s = right[s][j];
}
}
return c <= right[s][0] and right[s][0] <= d ? jmp + 1 : -1;
}
Compilation message (stderr)
jumps.cpp: In function 'void init(int, std::vector<int>)': jumps.cpp:11:63: error: 'mx' was not declared in this scope 11 | vector<vector<int>>(n, vector<int>(lg)), left, right, mx; | ^~ jumps.cpp:17:23: warning: pointer to a function used in arithmetic [-Wpointer-arith] 17 | left[i][0] = que.empty() ? i : que.top(); | ^ jumps.cpp:17:26: warning: pointer to a function used in arithmetic [-Wpointer-arith] 17 | left[i][0] = que.empty() ? i : que.top(); | ^ jumps.cpp:17:28: error: assignment of read-only location '*(std::left + ((sizetype)i))' 17 | left[i][0] = que.empty() ? i : que.top(); | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ jumps.cpp:27:24: warning: pointer to a function used in arithmetic [-Wpointer-arith] 27 | right[i][0] = que.empty() ? i : que.top(); | ^ jumps.cpp:27:27: warning: pointer to a function used in arithmetic [-Wpointer-arith] 27 | right[i][0] = que.empty() ? i : que.top(); | ^ jumps.cpp:27:29: error: assignment of read-only location '*(std::right + ((sizetype)i))' 27 | right[i][0] = que.empty() ? i : que.top(); | ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ jumps.cpp:31:33: warning: pointer to a function used in arithmetic [-Wpointer-arith] 31 | if(height[left[i][0]] > height[right[i][0]]){ | ^ jumps.cpp:31:36: warning: pointer to a function used in arithmetic [-Wpointer-arith] 31 | if(height[left[i][0]] > height[right[i][0]]){ | ^ jumps.cpp:31:36: error: invalid conversion from 'std::ios_base& (*)(std::ios_base&)' to 'std::vector<int>::size_type' {aka 'long unsigned int'} [-fpermissive] 31 | if(height[left[i][0]] > height[right[i][0]]){ | ~~~~~~~~~^ | | | std::ios_base& (*)(std::ios_base&) In file included from /usr/include/c++/11/vector:67, from jumps.h:1, from jumps.cpp:1: /usr/include/c++/11/bits/stl_vector.h:1043:28: note: initializing argument 1 of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::reference = int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]' 1043 | operator[](size_type __n) _GLIBCXX_NOEXCEPT | ~~~~~~~~~~^~~ jumps.cpp:31:55: warning: pointer to a function used in arithmetic [-Wpointer-arith] 31 | if(height[left[i][0]] > height[right[i][0]]){ | ^ jumps.cpp:31:58: warning: pointer to a function used in arithmetic [-Wpointer-arith] 31 | if(height[left[i][0]] > height[right[i][0]]){ | ^ jumps.cpp:31:58: error: invalid conversion from 'std::ios_base& (*)(std::ios_base&)' to 'std::vector<int>::size_type' {aka 'long unsigned int'} [-fpermissive] 31 | if(height[left[i][0]] > height[right[i][0]]){ | ~~~~~~~~~~^ | | | std::ios_base& (*)(std::ios_base&) In file included from /usr/include/c++/11/vector:67, from jumps.h:1, from jumps.cpp:1: /usr/include/c++/11/bits/stl_vector.h:1043:28: note: initializing argument 1 of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::reference = int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]' 1043 | operator[](size_type __n) _GLIBCXX_NOEXCEPT | ~~~~~~~~~~^~~ jumps.cpp:32:42: warning: pointer to a function used in arithmetic [-Wpointer-arith] 32 | mx[i][0] = left[i][0]; | ^ jumps.cpp:32:45: warning: pointer to a function used in arithmetic [-Wpointer-arith] 32 | mx[i][0] = left[i][0]; | ^ jumps.cpp:35:43: warning: pointer to a function used in arithmetic [-Wpointer-arith] 35 | mx[i][0] = right[i][0]; | ^ jumps.cpp:35:46: warning: pointer to a function used in arithmetic [-Wpointer-arith] 35 | mx[i][0] = right[i][0]; | ^ jumps.cpp:40:31: warning: pointer to a function used in arithmetic [-Wpointer-arith] 40 | left[i][j] = left[left[i][j - 1]][j - 1]; | ^ jumps.cpp:40:34: warning: pointer to a function used in arithmetic [-Wpointer-arith] 40 | left[i][j] = left[left[i][j - 1]][j - 1]; | ^ jumps.cpp:40:49: warning: pointer to a function used in arithmetic [-Wpointer-arith] 40 | left[i][j] = left[left[i][j - 1]][j - 1]; | ^ jumps.cpp:40:56: warning: pointer to a function used in arithmetic [-Wpointer-arith] 40 | left[i][j] = left[left[i][j - 1]][j - 1]; | ^ cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith] jumps.cpp:40:42: error: invalid types 'std::ios_base&(std::ios_base&)[std::ios_base&(std::ios_base&)]' for array subscript 40 | left[i][j] = left[left[i][j - 1]][j - 1]; | ^ jumps.cpp:41:32: warning: pointer to a function used in arithmetic [-Wpointer-arith] 41 | right[i][j] = right[right[i][j - 1]][j - 1]; | ^ jumps.cpp:41:35: warning: pointer to a function used in arithmetic [-Wpointer-arith] 41 | right[i][j] = right[right[i][j - 1]][j - 1]; | ^ jumps.cpp:41:52: warning: pointer to a function used in arithmetic [-Wpointer-arith] 41 | right[i][j] = right[right[i][j - 1]][j - 1]; | ^ jumps.cpp:41:59: warning: pointer to a function used in arithmetic [-Wpointer-arith] 41 | right[i][j] = right[right[i][j - 1]][j - 1]; | ^ cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith] jumps.cpp:41:44: error: invalid types 'std::ios_base&(std::ios_base&)[std::ios_base&(std::ios_base&)]' for array subscript 41 | right[i][j] = right[right[i][j - 1]][j - 1]; | ^ jumps.cpp: In function 'int minimum_jumps(int, int, int, int)': jumps.cpp:52:27: warning: pointer to a function used in arithmetic [-Wpointer-arith] 52 | if(right[b][0] <= d){ | ^ jumps.cpp:52:30: warning: pointer to a function used in arithmetic [-Wpointer-arith] 52 | if(right[b][0] <= d){ | ^ jumps.cpp:52:32: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] 52 | if(right[b][0] <= d){ | ~~~~~~~~~~~~^~~~ jumps.cpp:57:19: error: 'l' was not declared in this scope 57 | int mid = l; | ^ jumps.cpp:59:35: error: 'r' was not declared in this scope 59 | if(right[l][j] <= r){ | ^ jumps.cpp:63:12: error: 'height' was not declared in this scope 63 | if(height[b] > height[mid]){ | ^~~~~~ jumps.cpp:64:27: warning: pointer to a function used in arithmetic [-Wpointer-arith] 64 | if(right[b][0] <= d){ | ^ jumps.cpp:64:30: warning: pointer to a function used in arithmetic [-Wpointer-arith] 64 | if(right[b][0] <= d){ | ^ jumps.cpp:64:32: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] 64 | if(right[b][0] <= d){ | ~~~~~~~~~~~~^~~~ jumps.cpp:71:31: warning: pointer to a function used in arithmetic [-Wpointer-arith] 71 | if(a <= left[s][j] and height[left[s][j]] < height[mid]){ | ^ jumps.cpp:71:34: warning: pointer to a function used in arithmetic [-Wpointer-arith] 71 | if(a <= left[s][j] and height[left[s][j]] < height[mid]){ | ^ jumps.cpp:71:22: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] 71 | if(a <= left[s][j] and height[left[s][j]] < height[mid]){ | ~~^~~~~~~~~~~~~ jumps.cpp:71:40: error: 'height' was not declared in this scope 71 | if(a <= left[s][j] and height[left[s][j]] < height[mid]){ | ^~~~~~ jumps.cpp:71:53: warning: pointer to a function used in arithmetic [-Wpointer-arith] 71 | if(a <= left[s][j] and height[left[s][j]] < height[mid]){ | ^ jumps.cpp:71:56: warning: pointer to a function used in arithmetic [-Wpointer-arith] 71 | if(a <= left[s][j] and height[left[s][j]] < height[mid]){ | ^ jumps.cpp:72:35: warning: pointer to a function used in arithmetic [-Wpointer-arith] 72 | s = left[s][j]; | ^ jumps.cpp:72:38: warning: pointer to a function used in arithmetic [-Wpointer-arith] 72 | s = left[s][j]; | ^ jumps.cpp:72:38: error: invalid conversion from 'std::ios_base& (*)(std::ios_base&)' to 'int' [-fpermissive] 72 | s = left[s][j]; | ~~~~~~~~~^ | | | std::ios_base& (*)(std::ios_base&) jumps.cpp:76:23: warning: pointer to a function used in arithmetic [-Wpointer-arith] 76 | if(a <= left[s][0]){ | ^ jumps.cpp:76:26: warning: pointer to a function used in arithmetic [-Wpointer-arith] 76 | if(a <= left[s][0]){ | ^ jumps.cpp:76:14: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] 76 | if(a <= left[s][0]){ | ~~^~~~~~~~~~~~~ jumps.cpp:77:32: warning: pointer to a function used in arithmetic [-Wpointer-arith] 77 | if(right[left[s][0]][0] <= d){ | ^ jumps.cpp:77:35: warning: pointer to a function used in arithmetic [-Wpointer-arith] 77 | if(right[left[s][0]][0] <= d){ | ^ jumps.cpp:77:25: error: invalid types 'std::ios_base&(std::ios_base&)[std::ios_base&(std::ios_base&)]' for array subscript 77 | if(right[left[s][0]][0] <= d){ | ^ jumps.cpp:83:28: error: 'height' was not declared in this scope 83 | if(height[mx[s][j]] <= height[mid]){ | ^~~~~~ jumps.cpp:83:35: error: 'mx' was not declared in this scope 83 | if(height[mx[s][j]] <= height[mid]){ | ^~ jumps.cpp:89:39: warning: pointer to a function used in arithmetic [-Wpointer-arith] 89 | return right[s][0] <= d ? jmp + 1 : -1; | ^ jumps.cpp:89:42: warning: pointer to a function used in arithmetic [-Wpointer-arith] 89 | return right[s][0] <= d ? jmp + 1 : -1; | ^ jumps.cpp:89:44: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] 89 | return right[s][0] <= d ? jmp + 1 : -1; | ~~~~~~~~~~~~^~~~ jumps.cpp:91:30: warning: pointer to a function used in arithmetic [-Wpointer-arith] 91 | if(0 < left[s][0] and right[left[s][0]][0] <= d){ | ^ jumps.cpp:91:33: warning: pointer to a function used in arithmetic [-Wpointer-arith] 91 | if(0 < left[s][0] and right[left[s][0]][0] <= d){ | ^ jumps.cpp:91:22: error: ordered comparison of pointer with integer zero ('int' and 'std::ios_base& (*)(std::ios_base&)') 91 | if(0 < left[s][0] and right[left[s][0]][0] <= d){ | ~~^~~~~~~~~~~~ jumps.cpp:91:51: warning: pointer to a function used in arithmetic [-Wpointer-arith] 91 | if(0 < left[s][0] and right[left[s][0]][0] <= d){ | ^ jumps.cpp:91:54: warning: pointer to a function used in arithmetic [-Wpointer-arith] 91 | if(0 < left[s][0] and right[left[s][0]][0] <= d){ | ^ jumps.cpp:91:44: error: invalid types 'std::ios_base&(std::ios_base&)[std::ios_base&(std::ios_base&)]' for array subscript 91 | if(0 < left[s][0] and right[left[s][0]][0] <= d){ | ^ jumps.cpp:96:27: warning: pointer to a function used in arithmetic [-Wpointer-arith] 96 | if(right[s][j] < c){ | ^ jumps.cpp:96:30: warning: pointer to a function used in arithmetic [-Wpointer-arith] 96 | if(right[s][j] < c){ | ^ jumps.cpp:96:32: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] 96 | if(right[s][j] < c){ | ~~~~~~~~~~~~^~~ jumps.cpp:98:36: warning: pointer to a function used in arithmetic [-Wpointer-arith] 98 | s = right[s][j]; | ^ jumps.cpp:98:39: warning: pointer to a function used in arithmetic [-Wpointer-arith] 98 | s = right[s][j]; | ^ jumps.cpp:98:39: error: invalid conversion from 'std::ios_base& (*)(std::ios_base&)' to 'int' [-fpermissive] 98 | s = right[s][j]; | ~~~~~~~~~~^ | | | std::ios_base& (*)(std::ios_base&) jumps.cpp:101:28: warning: pointer to a function used in arithmetic [-Wpointer-arith] 101 | return c <= right[s][0] and right[s][0] <= d ? jmp + 1 : -1; | ^ jumps.cpp:101:31: warning: pointer to a function used in arithmetic [-Wpointer-arith] 101 | return c <= right[s][0] and right[s][0] <= d ? jmp + 1 : -1; | ^ jumps.cpp:101:18: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] 101 | return c <= right[s][0] and right[s][0] <= d ? jmp + 1 : -1; | ~~^~~~~~~~~~~~~~ jumps.cpp:101:44: warning: pointer to a function used in arithmetic [-Wpointer-arith] 101 | return c <= right[s][0] and right[s][0] <= d ? jmp + 1 : -1; | ^ jumps.cpp:101:47: warning: pointer to a function used in arithmetic [-Wpointer-arith] 101 | return c <= right[s][0] and right[s][0] <= d ? jmp + 1 : -1; | ^ jumps.cpp:101:49: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] 101 | return c <= right[s][0] and right[s][0] <= d ? jmp + 1 : -1; | ~~~~~~~~~~~~^~~~