#include "bits/stdc++.h"
#include "elephants.h"
using namespace std;
int n, l;
int *x;
vector<int> pos;
vector<int> ele;
void init(int N, int L, int X[])
{
n = N;
l = L;
x = X;
pos.resize(n);
ele.resize(n);
for(int i = 0; i<n; i++)
{
pos[i] = i;
ele[i] = x[i];
}
}
int solve()
{
int len = x[0];
len+=l;
int res = 1;
int j = 1;
while(j<n)
{
while(j<n&&x[j]<=len)
j++;
res++;
len = x[j]+l;
}
return res-1;
}
int get_max()
{
int maxi = 0;
for(int j = 0; j<n; j++)
maxi = max(maxi, x[j]);
return maxi;
}
void count_sort(int e)
{
vector<int> book(10, 0);
for(int j = 0; j<n; j++)
book[(x[j]/e)%10]++;
/*for(int j = 0; j<10; j++)
cout << book[j] << ' ';
cout << endl;*/
int output[n];
for(int j = 1; j<10; j++)
book[j]+=book[j-1];
for(int j = n-1; j>=0; j--)
{
output[book[(x[j]/e)%10]-1] = x[j];
book[(x[j]/e)%10]--;
}
for(int j = 0; j<n; j++)
x[j] = output[j];
}
void radix_sort()
{
int m = get_max();
for(int e = 1; m/e>0; e*=10)
count_sort(e);
}
int update(int i, int y)
{
int ind = lower_bound(x, x+n, ele[i]) - x;
x[ind] = y;
ele[i] = y;
radix_sort();
/*for(int j = 0; j<n; j++)
cout << x[j] << ' ';
cout << endl;*/
int res = solve();
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
3 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
3 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Execution timed out |
9094 ms |
972 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
3 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Execution timed out |
9094 ms |
972 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
3 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Execution timed out |
9094 ms |
972 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |