#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
int* v;
using vi = vector<int>;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, K;
cin >> N >> K;
map<int, int> ct;
v = new int[1+N];
for(int i = 1; i <= N; i++)
{
cin >> v[i];
ct[v[i]] = 0;
}
int x = -1;
for(auto& z : ct) z.second = ++x;
for(int i = 1; i <= N; i++) v[i] = ct[v[i]] / K;
vi BIT(1+N, 0);
vi I(N);
iota(I.begin(), I.end(), 1);
sort(I.begin(), I.end(), [] (int p, int q)
{
if(v[p] == v[q]) return p < q;
else return v[p] < v[q];
});
int res = N;
// for(int i = 1; i <= N; i++) cerr << v[i] << ' ';
// cerr << '\n';
for(int i : I)
{
// cerr << "\n\n";
// cerr << "i = " << i << '\n';
int curr = 1;
// for(int z = 1; z <= N; z++) cerr << BIT[z] << ' ';
// cerr << "\n";
for(int j = i-1; j >= 1; j -= j&-j)
curr = max(curr, BIT[j] + 1);
// cerr << "curr = " << curr << '\n';
res = min(res, N - curr);
for(int j = i; j <= N; j += j&-j)
BIT[j] = max(BIT[j], curr);
}
cout << res << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
4 ms |
580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
588 KB |
Output is correct |
2 |
Correct |
3 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
588 KB |
Output is correct |
2 |
Correct |
3 ms |
576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
588 KB |
Output is correct |
2 |
Correct |
3 ms |
588 KB |
Output is correct |