#include <iostream>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
typedef long long ll;
ll linf = 1e15+1;
inline void scoobydoobydoo(){
ios::sync_with_stdio(false);
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
map<ll, ll> valToIndex;
int main(){
scoobydoobydoo();
int n, k; cin >> n >> k;
vector<int> v(n);
for (int i = 0; i < n; i++)cin >> v[i];
vector<int> t = v;
sort(rall(t));
for (int i = 0; i < n; i++){
valToIndex[t[i]] = i/k + 1;
}
for (int i = 0; i < n; i++)v[i] = valToIndex[v[i]];
reverse(all(v));
//for (int i = 0; i < n; i++)cout << v[i] << " ";
//cout << endl;
set<pair<ll, ll> > s; //value, dp
ll dp[200001];
if (v.size() == 0){
cout << n << endl;
return 0;
}
dp[0] = 1;
s.insert({0, 0});
s.insert({v[0], 1});
for (int i = 1; i < v.size(); i++){
auto it = s.upper_bound({v[i], 10000000});
it--;
dp[i] = (*it).second + 1;
if ((*it).first == v[i])s.erase(it);
s.insert({v[i], dp[i]});
while (true){
auto itr = s.find({v[i], dp[i]});
itr++;
if (itr == s.end())break;
if ((*itr).second > dp[i])break;
s.erase(itr);
}
}
cout << n - (*s.rbegin()).second << endl;
return 0;
}
Compilation message
studentsko.cpp: In function 'int main()':
studentsko.cpp:62:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for (int i = 1; i < v.size(); i++){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
604 KB |
Output is correct |
2 |
Correct |
3 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
860 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
860 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1068 KB |
Output is correct |
2 |
Correct |
3 ms |
600 KB |
Output is correct |