이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "elephants.h"
#include<bits/stdc++.h>
using namespace std;
const int blsz = 400;
const int maxn = 2e5+5;
const int INF = 2e9+5;
map<int, int> sp[18];
multiset<int> current;
multiset<int> changed;
int A[maxn];
int n, l;
void build_sp(){
changed = {INF};
sp[0].clear();
for(auto v: current){
if(v == INF)continue;
sp[0][v] = *current.upper_bound(v + l);
}
sp[0][INF] = INF;
for(int i = 1; i < 18; i++){
sp[i].clear();
for(auto v: current){
sp[i][v] = sp[i-1][sp[i-1][v]];
}
}
}
void init(int N, int L, int X[])
{
n = N;
l = L;
current.insert(INF);
for(int i = 0; i < N; i++){
A[i] = X[i];
current.insert(A[i]);
}
build_sp();
}
int update(int i, int y)
{
current.erase(current.find(A[i]));
changed.insert(A[i]);
A[i] = y;
current.insert(A[i]);
changed.insert(A[i]);
int realcnt = 0, ans = 0;
int pos = *current.begin();
while(pos != INF){
realcnt++;
if(changed.find(pos) != changed.end()){
if(current.find(pos) == current.end())pos = *current.upper_bound(pos);
else {
ans++;
pos = *current.upper_bound(pos + l);
}
}
else {
int nxt_change = *changed.upper_bound(pos);
for(int i = 17; i >= 0; i--){
if(sp[i][pos] < nxt_change){
pos = sp[i][pos];
ans += (1<<i);
}
}
pos = *current.upper_bound(pos + l);
ans++;
}
}
if(realcnt >= blsz)build_sp();
return ans;
}
# | 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... |