Submission #211137

# Submission time Handle Problem Language Result Execution time Memory
211137 2020-03-19T10:08:29 Z Fasho Studentsko (COCI14_studentsko) C++14
100 / 100
7 ms 512 KB
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
#define ull unsigned long long int
using namespace std;

ll n,m,ar[N],sum,t,k,tut[N],b=0;

lli p[N];

bool cmp(lli a,lli b)
{
	return a.se<b.se;
}

ll bs(ll x,ll r)
{
	ll l=0;
	// cout<<"[d]"<<sp<<x<<sp<<r<<sp<<tut[r]<<sp;
	while(l<r)
	{
		if(l==r-1)
		{
			if(tut[r]<=x)
				l=r;
			break;
		}
		int mid=(l+r)/2;
		if(tut[mid]<=x)
			l=mid;
		else
			r=mid-1;
	}
	// cout<<l<<endl;
	return l;
}

ll lis()
{
	for(int i=1;i<=n;i++)
	{
		ll x=bs(ar[i],b);
		// cout<<ar[i]<<sp<<x<<sp<<b<<sp<<tut[x+1]<<endl;
		if(x==b)
			b++,tut[b]=ar[i];
		x++;
		tut[x]=min(tut[x],ar[i]);
	}
	return b;

}

int main()
{
	fast;
	cin>>n>>k;
	fo(i,1,n)
	cin>>p[i].fi,p[i].se=i;
	sort(p+1,p+n+1);
	fo(i,1,n)
		p[i].fi=(i+k-1)/k;
	sort(p+1,p+n+1,cmp);
	fo(i,1,n)
		ar[i]=p[i].fi;
	// cout<<endl;
	// 	fo(i,1,n)
		// cout<<ar[i]<<sp;
	// cout<<endl;
	cout<<n-lis();
	// cout<<endl;
		// fo(i,1,n)
		// cout<<tut[i]<<sp;
}

# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 416 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 7 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 7 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 7 ms 512 KB Output is correct