제출 #1282876

#제출 시각아이디문제언어결과실행 시간메모리
1282876tranbahien0Rabbit Carrot (LMIO19_triusis)C++20
0 / 100
3 ms580 KiB
#include <bits/stdc++.h> #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define FOD(i, a, b) for(int i = (a); i >= (b); i--) #define file(name) if(fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } #define el cout << '\n' #define maxn int(2e5 + 5) using namespace std; int n, m, k, res, a[maxn], dp[maxn], t[maxn << 1]; vector<int> vals; /** a[i] - a[j] <= k <=> a[j] >= a[i] - k **/ void update(int x, int v) { for(; x; x -= x & -x) t[x] = max(t[x], v); } int get(int x) { int res = 0; for(; x <= m; x += x & -x) res = max(res, t[x]); return res; } void compress() { FOR(i, 1, n) vals.push_back(a[i]), vals.push_back(a[i] - k); sort(vals.begin(), vals.end()); vals.resize(unique(vals.begin(), vals.end()) - vals.begin()); m = vals.size(); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; FOR(i, 1, n) cin >> a[i]; compress(); FOR(i, 1, n) { int x = lower_bound(vals.begin(), vals.end(), a[i]) - vals.begin() + 1; int y = lower_bound(vals.begin(), vals.end(), a[i] - k) - vals.begin() + 1; if(max(get(x), get(y)) == 0) dp[i] = (a[i] <= k); else dp[i] = max(get(x), get(y)) + 1; update(x, dp[i]); res = max(res, dp[i]); } cout << n - res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...