답안 #547962

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547962 2022-04-12T05:01:32 Z PikaQ Rabbit Carrot (LMIO19_triusis) C++17
0 / 100
10 ms 13108 KB
#include<bits/stdc++.h>
#define int ll
#define forn(i,n) for(int i=0;i<(n);i++)
#define Forn(i,n) for(int i=1;i<=(n);i++)
#define ll long long
#define pb push_back
#define F first
#define S second
#define vi vector<long long>
#define pii pair<int,int>
#define all(p) p.begin(),p.end()
#define st0(p) memset((p),0,sizeof(p))
#define sz(x) (x).size()
#define rz resize
using namespace std;

 
inline void USACO(string filename){
  freopen((filename+".in").c_str(),"r",stdin);
  freopen((filename+".out").c_str(),"w",stdout);
}
 
void debug() {cout << endl;}
template <class T, class ...U> void debug(T a, U ... b) { cerr << a << " "; debug(b...);}
const int N = (int) 2e5 + 9;
const int INF = (int) 1e9 + 7;
int n,k;

struct SegmentTree{
	int t[N<<2];
	void init(){
		for(auto &i : t) i = -INF;
	}
	void modify(int l,int r,int p,int v,int id){
		if(l == r){
			t[id] = v;
			return;
		}
		int m = (l+r)/2;
		if(p <= m) modify(l,m,p,v,2*id);
		else modify(m+1,r,p,v,2*id+1);
		t[id] = max(t[2*id],t[2*id+1]);
	}
	int query(int ql,int qr,int l,int r,int id){
		if(ql <= l  && qr >= r){
			return t[id];
		}
		int m = (l+r)/2;
		if(qr <= m) return query(ql,qr,l,m,2*id);
		else if(ql > m) return query(ql,qr,m+1,r,2*id+1);
		else return max(query(ql,qr,l,m,2*id),query(ql,qr,m+1,r,2*id+1));
	}
}seg;

void solve(){
	cin >> n >> k;
	vi a(n),rk(n);
	forn(i,n) cin >> a[i],rk[i] = a[i];
	rk.pb(0);
	sort(all(rk));
	rk.resize(unique(all(rk)) - rk.begin());
	vi lm(rk.size()+1);
	int cur = 0;
	Forn(i,n){
		while(rk[i] - rk[cur] > k){
			cur++;
		}
		lm[i+1] = cur+1;
	}
	forn(i,n) a[i] = upper_bound(all(rk),a[i]) - rk.begin();
	vi dp(n);
	seg.init();
	seg.modify(1,n+1,1,0,1);
	forn(i,n){
		dp[i] = seg.query(lm[a[i]],n+1,1,n+1,1) + 1;
		seg.modify(1,n+1,a[i],dp[i],1);
	}
	cout <<((n - seg.query(1,n+1,1,n+1,1) < 0) ? n : (n - seg.query(1,n+1,1,n+1,1))) << '\n';
}
signed main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Runtime error 10 ms 13108 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Runtime error 10 ms 13108 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Runtime error 10 ms 13108 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 3 ms 6484 KB Output is correct
3 Runtime error 10 ms 13108 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -