//#pragma GCC optimize("O3")
#include "elephants.h"
#include <bits/stdc++.h>
using namespace std;
int n, l;
vector<int> v;
vector<int> po;
vector<int> haspo;
void init(int N, int L, int X[])
{
n = N;
l = L;
v.resize(n);
po.resize(n);
haspo.resize(n);
for (int i = 0; i < n; i++) {
po[i] = i;
haspo[i] = i;
v[i] = X[i];
}
}
int update(int i, int y) {
if (v[po[i]] < y) {
v[po[i]] = y;
int lst, qtd = 0;
for (int i = 0; i < n; i++) {
if ((i < (n - 1)) && (v[i] > v[i + 1])) {
swap(v[i], v[i + 1]);
swap(po[haspo[i]], po[haspo[i + 1]]);
swap(haspo[i], haspo[i + 1]);
}
if ((i == 0) || (v[i] > (lst + l))) {
lst = v[i];
qtd++;
}
}
return qtd;
} else {
v[po[i]] = y;
int lst, qtd = 0;
for (int i = n - 1; i >= 0; i--) {
if ((i > 0) && (v[i] < v[i - 1])) {
swap(v[i], v[i - 1]);
swap(po[haspo[i]], po[haspo[i - 1]]);
swap(haspo[i], haspo[i - 1]);
}
if ((i == (n - 1)) || (v[i] < (lst - l))) {
lst = v[i];
qtd++;
}
}
return qtd;
}
}
Compilation message
elephants.cpp: In function 'int update(int, int)':
elephants.cpp:51:42: warning: 'lst' may be used uninitialized in this function [-Wmaybe-uninitialized]
51 | if ((i == (n - 1)) || (v[i] < (lst - l))) {
| ~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
Output is correct |
2 |
Correct |
1 ms |
6480 KB |
Output is correct |
3 |
Correct |
2 ms |
6652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
Output is correct |
2 |
Correct |
1 ms |
6480 KB |
Output is correct |
3 |
Correct |
2 ms |
6652 KB |
Output is correct |
4 |
Correct |
2 ms |
6480 KB |
Output is correct |
5 |
Correct |
2 ms |
6480 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
Output is correct |
2 |
Correct |
1 ms |
6480 KB |
Output is correct |
3 |
Correct |
2 ms |
6652 KB |
Output is correct |
4 |
Correct |
2 ms |
6480 KB |
Output is correct |
5 |
Correct |
2 ms |
6480 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
7 |
Correct |
2109 ms |
8960 KB |
Output is correct |
8 |
Correct |
3177 ms |
9252 KB |
Output is correct |
9 |
Correct |
3713 ms |
9924 KB |
Output is correct |
10 |
Correct |
6944 ms |
9404 KB |
Output is correct |
11 |
Correct |
7414 ms |
10680 KB |
Output is correct |
12 |
Execution timed out |
9034 ms |
10832 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
Output is correct |
2 |
Correct |
1 ms |
6480 KB |
Output is correct |
3 |
Correct |
2 ms |
6652 KB |
Output is correct |
4 |
Correct |
2 ms |
6480 KB |
Output is correct |
5 |
Correct |
2 ms |
6480 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
7 |
Correct |
2109 ms |
8960 KB |
Output is correct |
8 |
Correct |
3177 ms |
9252 KB |
Output is correct |
9 |
Correct |
3713 ms |
9924 KB |
Output is correct |
10 |
Correct |
6944 ms |
9404 KB |
Output is correct |
11 |
Correct |
7414 ms |
10680 KB |
Output is correct |
12 |
Execution timed out |
9034 ms |
10832 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
Output is correct |
2 |
Correct |
1 ms |
6480 KB |
Output is correct |
3 |
Correct |
2 ms |
6652 KB |
Output is correct |
4 |
Correct |
2 ms |
6480 KB |
Output is correct |
5 |
Correct |
2 ms |
6480 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
7 |
Correct |
2109 ms |
8960 KB |
Output is correct |
8 |
Correct |
3177 ms |
9252 KB |
Output is correct |
9 |
Correct |
3713 ms |
9924 KB |
Output is correct |
10 |
Correct |
6944 ms |
9404 KB |
Output is correct |
11 |
Correct |
7414 ms |
10680 KB |
Output is correct |
12 |
Execution timed out |
9034 ms |
10832 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |