Submission #960236

# Submission time Handle Problem Language Result Execution time Memory
960236 2024-04-10T00:42:26 Z ezzzay Studentsko (COCI14_studentsko) C++14
100 / 100
4 ms 4748 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N=2e5+5;
int a[N];
bool vis[N];
int dp[N];
int st[4*N];
void update(int node, int L, int R, int idx, int val){
    if(L==R){
        st[node]=val;
        return ;
    }
    int mid=(L+R)/2;
    if(L<=idx and idx<=mid){
        update(node*2,L,mid,idx,val);
    }
    else {
        update(node*2+1,mid+1,R,idx,val);
    }
    st[node]=max(st[node*2],st[node*2+1]);
}
int find(int node, int L , int R, int l, int r){
    if(l>R or L>r)return 0;
    if(l<=L and R<=r)return st[node];
    int mid=(L+R)/2;
    return max( find(node*2,L,mid,l,r) , find(node*2+1,mid+1,R,l,r)) ;
}
signed main(){
	int n,k;
	cin>>n>>k;
	vector<pair<int,int>>vc;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		vc.pb({x,i});
	}
	sort(vc.begin(),vc.end());
	for(int i=0;i<n;i++){
		a[vc[i].ss]=i/k+1;
	}
	int ans=0;
	for(int i=1;i<=n;i++){
        dp[i]= find(1,1,n,1,a[i])+1;
        dp[i]=max(dp[i],1LL);
        ans=max(dp[i],ans);
        update(1,1,n,a[i],dp[i]);
    }
    cout<<n-ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 2 ms 4548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4700 KB Output is correct
2 Correct 4 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4700 KB Output is correct
2 Correct 4 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4700 KB Output is correct
2 Correct 3 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4700 KB Output is correct
2 Correct 3 ms 4708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4700 KB Output is correct
2 Correct 3 ms 4748 KB Output is correct