이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast")
#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;
}
}
컴파일 시 표준 에러 (stderr) 메시지
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |