#include <bits/stdc++.h>
#include <iostream>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#include <string>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <map>
using namespace std;
typedef long double ld;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
//#define int long long
#define double long double
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define lowbit(x) x & (-x);
#define inf 1e18
#define _inf -1e18
#define pyes cout << "YES" << endl
#define pno cout << "NO" << endl
#define inv(a) for (int& x: a) cin >> x;
#define llv(a) for (ll& x: a) cin >> x;
#define pri(a) for (int& x: a) cout << x << ' '
int const MOD = 998244353;
int const lg = 20;
int const block = 500;
// int block;
int const MAX = 3e5 + 1, N = 4000;
int n, m, q, k;
void bexuyen67() {
cin >> n >> k;
vector<int> a(n);
inv(a);
auto ord = a;
sort(all(ord));
int ans = n;
for (int& x: a){
x = lower_bound(all(ord), x) - ord.begin();
x /= k;
}
vector<int> long_sub(1, 0);
for (int x: a){
if (x >= long_sub.back())
long_sub.push_back(x);
else{
int id = upper_bound(all(long_sub), x) - long_sub.begin();
long_sub[id] = x;
}
}
cout << n - (int) long_sub.size() + 1 << '\n';
}
signed main() {
#ifdef binhball
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(15);
int t = 1;
// cin >> t;
while (t--)
bexuyen67();
}
Compilation message
studentsko.cpp: In function 'void bexuyen67()':
studentsko.cpp:42:11: warning: unused variable 'ans' [-Wunused-variable]
42 | int ans = n;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
532 KB |
Output is correct |
2 |
Correct |
2 ms |
524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
532 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |