이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#include "elephants.h"
const int MAX_N = 150'000, B = 500, INF = 2e9;
int N, L, LIM, X[MAX_N], Y[MAX_N], num[MAX_N], pos[MAX_N], q_;
vector<int> a[B];
void recalculate(int j) {
auto &c = a[j];
int sz = size(c), pt = sz;
for(int i = sz; --i >= 0; ) {
while(pt && X[c[i]] + L < X[c[pt-1]]) --pt;
num[c[i]] = pt < sz ? num[c[pt]] + 1 : 1;
pos[c[i]] = pt < sz ? pos[c[pt]] : X[c[i]] + L;
}
}
void reset() {
for(int i = 0, j = 0; i < LIM; i++) {
for(int &v : a[i]) pos[j++] = v;
a[i].clear();
}
for(int i = 0; i < N; i++) {
Y[pos[i]] = i/B;
a[i/B].push_back(pos[i]);
}
for(int i = 0; i < LIM; i++)
recalculate(i);
}
void init(int n, int l, int x[]) {
N = n, L = l, LIM = (N - 1)/B + 1;
for(int i = 0; i < N; i++) {
X[i] = x[i];
a[i/B].push_back(i);
}
reset();
}
int lowerB(int val, int j){
int r = -1;
for(int k=512; k/=2; )
while(r + k < (int)size(a[j]) && X[a[j][r+k]] < val) r += k;
return r + 1;
}
int update(int i, int y) {
int l = Y[i], p = 0;
while(a[l][p] != i) ++p;
a[l].erase(begin(a[l]) + p);
recalculate(l);
X[i] = y;
for(l = 0; l < LIM; l++)
if(!empty(a[l]) && X[a[l][0]] > X[i]) break;
if(l) --l;
p = lowerB(y, l);
Y[i] = l;
a[l].insert(begin(a[l]) + p, i);
recalculate(l);
if(!(++q_ % (B - 2))) reset();
int res = 0, curr = -1;
for(int k = 0; k < LIM; k++) {
if(empty(a[k]) || curr >= X[a[k].back()]) continue;
int j = lowerB(curr + 1, k);
res += num[a[k][j]];
curr = pos[a[k][j]];
}
return res;
}
# | 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... |