#include "elephants.h"
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
int n,sz=500,arr[150100],cnt,num,len;
vector<int>buckets[310],need[310],lst[310];
void recalc(int id){
if(buckets[id].empty())return;
need[id].resize(buckets[id].size(),0);
lst[id].resize(buckets[id].size(),0);
int k=buckets[id].size()-1,l=buckets[id].back();
while(k>=0&&buckets[id][k]>=l-len)
lst[id][k]=buckets[id][k]+len,need[id][k]=1,k--;
int x=buckets[id].size()-1;
while(k>=0){
while(buckets[id][x-1]>buckets[id][k]+len)x--;
lst[id][k]=lst[id][x];
need[id][k]=need[id][x]+1;
k--;
}
}
void recons(){
vector<int>thingys;
for(int i=0;i<num;buckets[i++].clear())
for(auto j:buckets[i])
thingys.push_back(j);
int x=thingys.size();
for(int i=0;i<num;recalc(i++))
for(int j=i*sz;j<min(i*sz+sz,x);j++)
buckets[i].push_back(thingys[j]);
}
int gedans(){
int pew=-1,cnt=0;
for(int i=0;i<num;i++){
int x=upper_bound(all(buckets[i]),pew)-buckets[i].begin();
if(x==buckets[i].size())continue;
cnt+=need[i][x];
pew=lst[i][x];
}
return cnt;
}
void init(int N, int L, int X[]) {
n = N;
len=L;
for(int i=0;i<N;i++)
buckets[0].push_back(arr[i]=X[i]);
num=(n+sz-1)/sz;
recons();
}
int update(int i, int y) {
cnt++;
int id=0;
for(int x=0;x<num;x++)
if(buckets[x].size()&&
buckets[x].back()>=arr[i]){
id=x; break;}
buckets[id].erase(lower_bound(all(buckets[id]),arr[i]));
recalc(id); arr[i]=y;
id=num-1;
for(int i=0;i<num;i++)
if(buckets[i].size()&&y<=buckets[i].back()){
id=i;break;}
buckets[id].insert(lower_bound(all(buckets[id]),y),y);
recalc(id);
if(cnt==sz)
cnt=0,recons();
return gedans();
}
Compilation message
elephants.cpp: In function 'int gedans()':
elephants.cpp:36:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | if(x==buckets[i].size())continue;
| ~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
129 ms |
2396 KB |
Output is correct |
8 |
Correct |
145 ms |
2948 KB |
Output is correct |
9 |
Correct |
177 ms |
4424 KB |
Output is correct |
10 |
Correct |
154 ms |
4144 KB |
Output is correct |
11 |
Correct |
178 ms |
4060 KB |
Output is correct |
12 |
Correct |
283 ms |
4656 KB |
Output is correct |
13 |
Correct |
199 ms |
3936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
129 ms |
2396 KB |
Output is correct |
8 |
Correct |
145 ms |
2948 KB |
Output is correct |
9 |
Correct |
177 ms |
4424 KB |
Output is correct |
10 |
Correct |
154 ms |
4144 KB |
Output is correct |
11 |
Correct |
178 ms |
4060 KB |
Output is correct |
12 |
Correct |
283 ms |
4656 KB |
Output is correct |
13 |
Correct |
199 ms |
3936 KB |
Output is correct |
14 |
Correct |
138 ms |
3648 KB |
Output is correct |
15 |
Correct |
193 ms |
3748 KB |
Output is correct |
16 |
Correct |
513 ms |
5144 KB |
Output is correct |
17 |
Correct |
535 ms |
6444 KB |
Output is correct |
18 |
Correct |
602 ms |
6392 KB |
Output is correct |
19 |
Correct |
304 ms |
5980 KB |
Output is correct |
20 |
Correct |
542 ms |
6444 KB |
Output is correct |
21 |
Correct |
497 ms |
6816 KB |
Output is correct |
22 |
Correct |
295 ms |
5440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
129 ms |
2396 KB |
Output is correct |
8 |
Correct |
145 ms |
2948 KB |
Output is correct |
9 |
Correct |
177 ms |
4424 KB |
Output is correct |
10 |
Correct |
154 ms |
4144 KB |
Output is correct |
11 |
Correct |
178 ms |
4060 KB |
Output is correct |
12 |
Correct |
283 ms |
4656 KB |
Output is correct |
13 |
Correct |
199 ms |
3936 KB |
Output is correct |
14 |
Correct |
138 ms |
3648 KB |
Output is correct |
15 |
Correct |
193 ms |
3748 KB |
Output is correct |
16 |
Correct |
513 ms |
5144 KB |
Output is correct |
17 |
Correct |
535 ms |
6444 KB |
Output is correct |
18 |
Correct |
602 ms |
6392 KB |
Output is correct |
19 |
Correct |
304 ms |
5980 KB |
Output is correct |
20 |
Correct |
542 ms |
6444 KB |
Output is correct |
21 |
Correct |
497 ms |
6816 KB |
Output is correct |
22 |
Correct |
295 ms |
5440 KB |
Output is correct |
23 |
Correct |
1406 ms |
13156 KB |
Output is correct |
24 |
Correct |
1441 ms |
13304 KB |
Output is correct |
25 |
Correct |
985 ms |
12908 KB |
Output is correct |
26 |
Correct |
1172 ms |
12600 KB |
Output is correct |
27 |
Correct |
1196 ms |
12332 KB |
Output is correct |
28 |
Correct |
426 ms |
5200 KB |
Output is correct |
29 |
Correct |
400 ms |
5204 KB |
Output is correct |
30 |
Correct |
413 ms |
5208 KB |
Output is correct |
31 |
Correct |
404 ms |
5200 KB |
Output is correct |
32 |
Correct |
925 ms |
11932 KB |
Output is correct |
33 |
Correct |
926 ms |
11248 KB |
Output is correct |
34 |
Correct |
1048 ms |
12120 KB |
Output is correct |
35 |
Correct |
926 ms |
14764 KB |
Output is correct |
36 |
Correct |
952 ms |
11844 KB |
Output is correct |
37 |
Correct |
1340 ms |
14024 KB |
Output is correct |
38 |
Correct |
1157 ms |
11128 KB |
Output is correct |
39 |
Correct |
963 ms |
12152 KB |
Output is correct |
40 |
Correct |
1117 ms |
11156 KB |
Output is correct |
41 |
Correct |
1850 ms |
13196 KB |
Output is correct |
42 |
Correct |
1889 ms |
13344 KB |
Output is correct |