#include <bits/stdc++.h>
#ifndef LOCAL
#include "elephants.h"
#endif // LOCAL
using namespace std;
int n, l;
vector<int> x;
map<int, int> cnt;
void init(int N, int L, int X[]){
n = N;
l = L;
x.resize(N);
for(int i = 0; i < N; ++i) x[i] = X[i];
for(int i = 0; i < N; ++i){
++cnt[X[i]];
}
}
int greedy(){
int last = -1, ans = 0;
for(auto [x, y] : cnt){
if(!y) assert(false);
if(last < x) ++ans, last = x + l;
}
return ans;
}
int update(int i, int y){
if(!(--cnt[x[i]])) cnt.erase(cnt.find(x[i]));
x[i] = y;
++cnt[x[i]];
return greedy();
}
#ifdef LOCAL
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int X[4] = {10, 15, 17, 20};
init(4, 10, X);
cout << update(2, 16) << '\n';
cout << update(1, 25) << '\n';
cout << update(3, 35) << '\n';
cout << update(0, 38) << '\n';
cout << update(2, 0) << '\n';
return 0;
}
#endif // LOCAL
Compilation message
elephants.cpp: In function 'int greedy()':
elephants.cpp:26:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
26 | for(auto [x, y] : cnt){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
Output is correct |
2 |
Correct |
1 ms |
6480 KB |
Output is correct |
3 |
Correct |
1 ms |
6480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
Output is correct |
2 |
Correct |
1 ms |
6480 KB |
Output is correct |
3 |
Correct |
1 ms |
6480 KB |
Output is correct |
4 |
Correct |
1 ms |
6480 KB |
Output is correct |
5 |
Correct |
2 ms |
6480 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
Output is correct |
2 |
Correct |
1 ms |
6480 KB |
Output is correct |
3 |
Correct |
1 ms |
6480 KB |
Output is correct |
4 |
Correct |
1 ms |
6480 KB |
Output is correct |
5 |
Correct |
2 ms |
6480 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
7 |
Correct |
3857 ms |
10348 KB |
Output is correct |
8 |
Correct |
6336 ms |
10716 KB |
Output is correct |
9 |
Execution timed out |
9064 ms |
12880 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
Output is correct |
2 |
Correct |
1 ms |
6480 KB |
Output is correct |
3 |
Correct |
1 ms |
6480 KB |
Output is correct |
4 |
Correct |
1 ms |
6480 KB |
Output is correct |
5 |
Correct |
2 ms |
6480 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
7 |
Correct |
3857 ms |
10348 KB |
Output is correct |
8 |
Correct |
6336 ms |
10716 KB |
Output is correct |
9 |
Execution timed out |
9064 ms |
12880 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
Output is correct |
2 |
Correct |
1 ms |
6480 KB |
Output is correct |
3 |
Correct |
1 ms |
6480 KB |
Output is correct |
4 |
Correct |
1 ms |
6480 KB |
Output is correct |
5 |
Correct |
2 ms |
6480 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
7 |
Correct |
3857 ms |
10348 KB |
Output is correct |
8 |
Correct |
6336 ms |
10716 KB |
Output is correct |
9 |
Execution timed out |
9064 ms |
12880 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |