This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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++){
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |