#include "elephants.h"
#include <map>
#include <unordered_map>
#include <set>
#include <iostream>
using namespace std;
const int N = 1e5 + 30;
const int T = 100;
int n, l, fr, sc;
int x[N];
map <int, int> mp;
unordered_map <int, int> nax, haj, a, b;
set <int> fp;
void go(int x)
{
int sm = 1, s = 0;
int nx = x, v = x;
while (s < T)
{
s++;
if (v > nx + l) sm++, nx = v;
if (v == sc) break;
v = haj[v];
}
a[x] = sm;
b[x] = nx + l;
}
void add(int x)
{
mp[x]++;
auto i1 = fp.lower_bound(x);
if (i1 != fp.end()) haj[x] = *i1, nax[*i1] = x;
if (i1 != fp.begin()) nax[x] = *(--i1), haj[*i1] = x;
fp.insert(x);
i1 = fp.end();
fr = *fp.begin(), sc = *(--i1);
int v = x;
for (int i = 0; i <= T + 1; i++)
{
go(v);
if (v == fr) break;
v = nax[v];
}
}
void rmv(int x)
{
mp[x]--;
if (x != sc && x != fr) haj[nax[x]] = haj[x], nax[haj[x]] = nax[x];
fp.erase(x);
auto i1 = fp.end();
fr = *fp.begin(), sc = *(--i1);
int v = x;
for (int i = 0; i <= T + 1; i++)
{
if (v == fr) break;
v = nax[v];
go(v);
}
}
int ans()
{
int v = fr, ret = 0;
while (v < sc)
{
ret += a[v];
if (b[v] >= sc) break;
v = *fp.lower_bound(b[v] + 1);
}
return ret;
}
void init(int N, int L, int X[])
{
n = N; l = L;
for (int i = 0; i < n; i++)
{
x[i] = X[i];
//cout << x[i] << endl;
if (mp[x[i]] == 0) add(x[i]);
else mp[x[i]]++;
}
}
int update(int i, int y)
{
if (mp[x[i]] == 1) rmv(x[i]);
else mp[x[i]]--;
x[i] = y;
if (mp[y] == 0) add(y);
else mp[y]++;
return ans();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
332 KB |
Output is correct |
2 |
Correct |
6 ms |
332 KB |
Output is correct |
3 |
Correct |
6 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
332 KB |
Output is correct |
2 |
Correct |
6 ms |
332 KB |
Output is correct |
3 |
Correct |
6 ms |
332 KB |
Output is correct |
4 |
Correct |
18 ms |
360 KB |
Output is correct |
5 |
Correct |
18 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
332 KB |
Output is correct |
2 |
Correct |
6 ms |
332 KB |
Output is correct |
3 |
Correct |
6 ms |
332 KB |
Output is correct |
4 |
Correct |
18 ms |
360 KB |
Output is correct |
5 |
Correct |
18 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Execution timed out |
9053 ms |
7600 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
332 KB |
Output is correct |
2 |
Correct |
6 ms |
332 KB |
Output is correct |
3 |
Correct |
6 ms |
332 KB |
Output is correct |
4 |
Correct |
18 ms |
360 KB |
Output is correct |
5 |
Correct |
18 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Execution timed out |
9053 ms |
7600 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
332 KB |
Output is correct |
2 |
Correct |
6 ms |
332 KB |
Output is correct |
3 |
Correct |
6 ms |
332 KB |
Output is correct |
4 |
Correct |
18 ms |
360 KB |
Output is correct |
5 |
Correct |
18 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Execution timed out |
9053 ms |
7600 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |