#include "elephants.h"
#define MAXN 500002
int n, l;
int elephants[MAXN];
int positions[MAXN];
void init(int N, int L, int X[])
{
l = L;
n = N;
for (int i=0; i < n; i++) {
elephants[i] = X[i];
positions[i] = X[i];
}
}
int update(int i, int y)
{
int result = 0;
int last_covered = -1;
int current_pos = elephants[i];
elephants[i] = y;
bool type = y < current_pos;
int carrying = -1;
bool eating = false;
for (int i = 0; i < n; i++) {
if (type) {
if (positions[i] > y ) {
carrying = positions[i];
positions[i] = y;
y = 2000000000;
} else if (carrying != -1) {
if (positions[i] == current_pos) {
positions[i] = carrying;
carrying = -1;
} else {
carrying ^= positions[i];
positions[i] ^= carrying;
carrying ^= positions[i];
}
}
}
else {
if (eating) {
if (positions[i+1] >= y) {
positions[i] = y;
eating = false;
} else {
positions[i] = positions[i+1];
}
} else if (positions[i] == current_pos) {
current_pos = -1;
eating = true;
i--;
continue;
}
}
if (last_covered < positions[i]) {
result++;
last_covered = positions[i] + l + 1;
}
}
return result;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |