이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "elephants.h"
#include <bits/stdc++.h>
using namespace std;
const int SQRT = 500, mxN = 150000;
int n, x[mxN+1], l, req[mxN], nx[mxN], blk[mxN], ucnt;
vector<int> blocks[SQRT];
void build_block(int b) {
int ne = blocks[b].size();
for (int i = blocks[b].size(); i--;) {
while (x[blocks[b][ne-1]] > x[blocks[b][i]] + l) ne--;
req[blocks[b][i]] = ne == blocks[b].size() ? 1 : req[blocks[b][ne]] + 1;
nx[blocks[b][i]] = ne == blocks[b].size() ? x[blocks[b][i]] + l + 1 : nx[blocks[b][ne]];
}
}
void rebuild() {
for (int i = 0; i < (n+SQRT-1)/SQRT; ++i) {
blocks[i].clear();
}
vector<int> order(n);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int a, int b){return x[a] < x[b];});
int b = 0;
for (int i = 0; i < n; ++i) {
blocks[b].push_back(order[i]);
blk[order[i]] = b;
if (blocks[b].size() == SQRT || i == n-1) {
build_block(b);
b++;
}
}
}
void init(int N, int L, int X[]) {
n = N;
l = L;
copy(X, X+n, x);
rebuild();
}
int update(int i, int y) {
ucnt++;
if (ucnt == SQRT) {
ucnt = 0;
rebuild();
}
blocks[blk[i]].erase(find(blocks[blk[i]].begin(), blocks[blk[i]].end(), i));
build_block(blk[i]);
x[i] = y;
for (int b = 0; b < (n+SQRT-1)/SQRT; ++b) {
if (b == (n+SQRT-1)/SQRT-1 || blocks[b].size() && x[blocks[b].back()] >= y) {
blk[i] = b;
blocks[b].insert(lower_bound(blocks[b].begin(), blocks[b].end(), i, [&](int a, int b){return x[a] < x[b];}), i);
build_block(b);
break;
}
}
int ans = 0;
x[n+1] = 0;
for (int b = 0; b < (n+SQRT-1)/SQRT; ++b) {
auto it = lower_bound(blocks[b].begin(), blocks[b].end(), n+1, [&](int a, int b){return x[a] < x[b];});
if (it != blocks[b].end()) {
ans += req[*it];
x[n+1] = nx[*it];
}
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
elephants.cpp: In function 'void build_block(int)':
elephants.cpp:13:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | req[blocks[b][i]] = ne == blocks[b].size() ? 1 : req[blocks[b][ne]] + 1;
| ~~~^~~~~~~~~~~~~~~~~~~
elephants.cpp:14:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | nx[blocks[b][i]] = ne == blocks[b].size() ? x[blocks[b][i]] + l + 1 : nx[blocks[b][ne]];
| ~~~^~~~~~~~~~~~~~~~~~~
elephants.cpp: In function 'int update(int, int)':
elephants.cpp:53:56: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
53 | if (b == (n+SQRT-1)/SQRT-1 || blocks[b].size() && x[blocks[b].back()] >= y) {
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |