Warning: session_start(): open(/var/lib/php/sessions/sess_9t7d60vvvtvl9ht965sp19vq5u, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
sclass MountainsAndValleys {
settable double[] values;
gettable new IntBuffer highs;
gettable new IntBuffer lows;
run {
int n = l(values);
if (n == 0) ret;
highs.add(0);
lows.add(0);
int i = 1;
while (i < n) {
// find plateau
var value = values[i];
int j = i+1;
while (j < n && values[j] == value) ++j;
// are we going up or down?
var last = values[i-1];
var list = value > last ? highs : lows;
//if (list.last() == i-1)
if (values[list.last()] == last)
list.popLast();
list.add(i);
i = j;
}
}
int prev(IntBuffer highsOrLows, int idx) {
int j = intBufferBinarySearch(highsOrLows, idx-1);
if (j >= 0) ret idx-1;
j = -j-1;
j--;
ret j >= 0 ? highsOrLows.get(j) : -1;
}
int next(IntBuffer highsOrLows, int idx) {
int j = intBufferBinarySearch(highsOrLows, idx+1);
if (j >= 0) ret idx+1;
j = -j-1;
ret j < l(highsOrLows) ? highsOrLows.get(j) : -1;
}
}