# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
140629 | Rouge_Hugo | 학생 (COCI14_studentsko) | C++11 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n,k;
int a[5005];
int tree[5005*3];
void update (int ind,int st,int end,int uind,int uval)
{
if (st==end)
{
tree[ind]=uval;
return ;
}
int m=(st+end)/2;
if (uind>m)update (ind*2+2,m+1,end,uind,uval);
else update(ind*2+1,st,m,uind,uval);
tree[ind]=max(tree[ind*2+1],tree[ind*2+2]);
}
query(int ind,int st,int end,int uind)
{
if (end<=uind)return tree[ind];
int m=(st+end)/2;
if (uind>m)return max(query(ind*2+1,st,m,uind),query (ind*2+2,m+1,end,uind));
else return query (ind*2+1,st,m,uind);
}
map<int,int>m;
int main()
{
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>a[i];
m[a[i]]++;
}
int r=0,re=0;
for(auto it:m)
{
re++;
re%=k;
m[it.first]=r;
if (re==0)r++;
}int mx=0;
k=n/k;
r=0;
for(int i=0;i<n;i+=1)
{ r=query(0,0,k-1,m[a[i]]);
// cout<<m[a[i]]<<" ";
mx=max(mx,r+1);
update (0,0,k-1,m[a[i]],r+1);
}
cout<<n-mx;
return 0;
}