#include "elephants.h"
#include <bits/stdc++.h>
using namespace std;
const int mxN=150000, B=550, mxBC=300;
int n, l, *x, uc, bc, r[mxBC];
map<int, int> mp;
vector<int> v[mxBC];
vector<array<int, 2>> w[mxBC];
void init(int N, int L, int X[])
{
n=N, l=L, x=X;
for(int i=0; i<n; ++i)
++mp[x[i]];
}
void bb(int i)
{
w[i]=vector<array<int, 2>>(v[i].size());
for(int j1=(int)v[i].size()-1, j2=v[i].size(); ~j1; --j1)
{
while(v[i][j2-1]>v[i][j1]+l)
--j2;
if(j2<v[i].size())
w[i][j1]= array<int, 2> {w[i][j2][0]+1, w[i][j2][1]};
else
w[i][j1]= array<int, 2> {1, v[i][j1]+l};
}
}
void bld()
{
bc=0;
for(pair<int, int> p : mp)
{
if(!bc||v[bc-1].size()>=B)
v[bc++].clear();
v[bc-1].push_back(p.first);
}
for(int i=0; i<bc; ++i)
{
if(i+1 < bc)
r[i]=v[i+1][0]-1;
else
r[i] = 1000000000;
bb(i);
}
}
void upd(int x, bool a)
{
int c=-1;
while(x>r[++c]);
int p=lower_bound(v[c].begin(), v[c].end(), x)-v[c].begin();
if(a)
v[c].insert(v[c].begin()+p, x);
else
v[c].erase(v[c].begin()+p);
bb(c);
}
int update(int i, int y)
{
if(uc++%B==0)
bld();
--mp[x[i]];
if(!mp[x[i]])
{
upd(x[i], 0);
mp.erase(x[i]);
}
if(!mp[y])
upd(y, 1);
++mp[y];
x[i]=y;
int a=0;
for(int i=0, c=-1; i<bc; ++i)
{
int p=upper_bound(v[i].begin(), v[i].end(), c)-v[i].begin();
if(p<v[i].size())
{
a+=w[i][p][0];
c=w[i][p][1];
}
}
return a;
}
Compilation message
elephants.cpp: In function 'void bb(int)':
elephants.cpp:25:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(j2<v[i].size())
~~^~~~~~~~~~~~
elephants.cpp: In function 'int update(int, int)':
elephants.cpp:80:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(p<v[i].size())
~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
296 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
296 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
361 ms |
1884 KB |
Output is correct |
8 |
Correct |
371 ms |
2412 KB |
Output is correct |
9 |
Correct |
514 ms |
4340 KB |
Output is correct |
10 |
Correct |
477 ms |
4344 KB |
Output is correct |
11 |
Correct |
542 ms |
4324 KB |
Output is correct |
12 |
Correct |
887 ms |
4452 KB |
Output is correct |
13 |
Correct |
498 ms |
4448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
296 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
361 ms |
1884 KB |
Output is correct |
8 |
Correct |
371 ms |
2412 KB |
Output is correct |
9 |
Correct |
514 ms |
4340 KB |
Output is correct |
10 |
Correct |
477 ms |
4344 KB |
Output is correct |
11 |
Correct |
542 ms |
4324 KB |
Output is correct |
12 |
Correct |
887 ms |
4452 KB |
Output is correct |
13 |
Correct |
498 ms |
4448 KB |
Output is correct |
14 |
Correct |
273 ms |
2700 KB |
Output is correct |
15 |
Correct |
551 ms |
2936 KB |
Output is correct |
16 |
Correct |
1337 ms |
4600 KB |
Output is correct |
17 |
Correct |
1488 ms |
6136 KB |
Output is correct |
18 |
Correct |
1607 ms |
6024 KB |
Output is correct |
19 |
Correct |
834 ms |
6008 KB |
Output is correct |
20 |
Correct |
1672 ms |
6008 KB |
Output is correct |
21 |
Correct |
1511 ms |
6132 KB |
Output is correct |
22 |
Correct |
765 ms |
6008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
296 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
361 ms |
1884 KB |
Output is correct |
8 |
Correct |
371 ms |
2412 KB |
Output is correct |
9 |
Correct |
514 ms |
4340 KB |
Output is correct |
10 |
Correct |
477 ms |
4344 KB |
Output is correct |
11 |
Correct |
542 ms |
4324 KB |
Output is correct |
12 |
Correct |
887 ms |
4452 KB |
Output is correct |
13 |
Correct |
498 ms |
4448 KB |
Output is correct |
14 |
Correct |
273 ms |
2700 KB |
Output is correct |
15 |
Correct |
551 ms |
2936 KB |
Output is correct |
16 |
Correct |
1337 ms |
4600 KB |
Output is correct |
17 |
Correct |
1488 ms |
6136 KB |
Output is correct |
18 |
Correct |
1607 ms |
6024 KB |
Output is correct |
19 |
Correct |
834 ms |
6008 KB |
Output is correct |
20 |
Correct |
1672 ms |
6008 KB |
Output is correct |
21 |
Correct |
1511 ms |
6132 KB |
Output is correct |
22 |
Correct |
765 ms |
6008 KB |
Output is correct |
23 |
Correct |
3768 ms |
12084 KB |
Output is correct |
24 |
Correct |
3852 ms |
12412 KB |
Output is correct |
25 |
Correct |
3128 ms |
12124 KB |
Output is correct |
26 |
Correct |
2990 ms |
12360 KB |
Output is correct |
27 |
Correct |
3181 ms |
12112 KB |
Output is correct |
28 |
Correct |
1944 ms |
2684 KB |
Output is correct |
29 |
Correct |
1835 ms |
2932 KB |
Output is correct |
30 |
Correct |
1910 ms |
2816 KB |
Output is correct |
31 |
Correct |
1828 ms |
2744 KB |
Output is correct |
32 |
Correct |
3771 ms |
12024 KB |
Output is correct |
33 |
Correct |
1382 ms |
12252 KB |
Output is correct |
34 |
Correct |
3144 ms |
12108 KB |
Output is correct |
35 |
Correct |
1402 ms |
12080 KB |
Output is correct |
36 |
Correct |
76 ms |
2784 KB |
Output is correct |
37 |
Correct |
2320 ms |
12384 KB |
Output is correct |
38 |
Correct |
3042 ms |
12288 KB |
Output is correct |
39 |
Correct |
2872 ms |
12236 KB |
Output is correct |
40 |
Correct |
3274 ms |
12104 KB |
Output is correct |
41 |
Correct |
6004 ms |
12548 KB |
Output is correct |
42 |
Correct |
6790 ms |
12380 KB |
Output is correct |