#include "elephants.h"
#include <bits/stdc++.h>
using namespace std;
const int mxN = 150007;
const int SZ = 388;
int n, l, step, pos[mxN], bkt[mxN], to[mxN], cnt[mxN], sz[SZ];
set<pair<int,int>> st;
pair<int,int> arr[SZ][2*SZ+7];
void fix(int b) {
int ind = sz[b]-1;
for (int i = sz[b]-1; i >= 0; --i) {
int val = arr[b][i].first + l;
while (ind && val < arr[b][ind-1].first) {
--ind;
}
if (val >= arr[b][sz[b]-1].first) {
to[arr[b][i].second] = val;
cnt[arr[b][i].second] = 1;
}
else {
to[arr[b][i].second] = to[ind];
cnt[arr[b][i].second] = cnt[ind] + 1;
}
}
}
void construct() {
for (int i = 0; i < SZ; ++i) {
sz[i] = 0;
}
auto it = st.begin();
for (int i = 0; i < n; ++i) {
bkt[it->second] = i/SZ;
arr[i/SZ][sz[i/SZ]++] = *it;
it++;
}
for (int b = 0; b < SZ; ++b) {
fix(b);
}
}
void init(int N, int L, int X[]) {
n = N, l = L;
for (int i = 0; i < n; ++i) {
pos[i] = X[i];
st.insert({pos[i], i});
}
construct();
}
int update(int i, int y) {
for (int j = 0; j < sz[bkt[i]]; ++j) {
if (arr[bkt[i]][j].second == i) {
arr[bkt[i]][j] = {INT_MAX,INT_MAX};
sort(arr[bkt[i]], arr[bkt[i]]+sz[bkt[i]]);
sz[bkt[i]]--;
break;
}
}
st.erase({pos[i], i});
fix(bkt[i]);
for (int b = 0; b < SZ; ++b) {
if (b == SZ-1 || (sz[b] && arr[b][sz[b]-1].first > y)) {
bkt[i] = b;
arr[b][sz[b]++] = {pos[i] = y, i};
sort(arr[b], arr[b]+sz[b]);
st.insert({pos[i], i});
fix(b);
break;
}
}
int ans = 0, cur = -1;
for (int b = 0; b < SZ; ++b) {
if (sz[b] && arr[b][sz[b]-1].first > cur) {
auto it = upper_bound(arr[b],arr[b]+sz[b],make_pair(cur,INT_MAX));
ans += cnt[it->second];
cur = to[it->second];
}
}
step++;
if (step == SZ) {
construct();
step = 0;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
10588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
10588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
10588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
10588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
10588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |