#include <bits/stdc++.h>
using namespace std ;
using ll = long long ;
struct SegTree {
int _n ;
struct Node {
ll value = 0 ;
Node() {}
Node(ll x) {
value = x ;
}
};
Node combine(Node l, Node r) {
if (l.value > r.value) return l ;
return r ;
}
vector<Node> t ;
SegTree(int len) {
_n = len ;
t.assign(len * 4 + 1, Node(0)) ;
}
void modify(int i, ll x, int v, int tl, int tr) {
if (tl == tr) {
t[v] = combine(t[v], x) ;
} else {
int tm = (tl + tr) >> 1 ;
if (i <= tm)
modify(i, x, v << 1, tl, tm) ;
else
modify(i, x, v << 1 | 1, tm + 1, tr) ;
t[v] = combine(t[v * 2], t[v * 2 + 1]) ;
}
}
void modify(int i, ll x) {
modify(i, x, 1, 1, _n) ;
}
Node get(int l, int r, int v, int tl, int tr) {
if (l > tr || r < tl) return Node(0) ;
if (l <= tl && tr <= r) return t[v] ;
int tm = (tl + tr) >> 1 ;
Node L = get(l, r, v << 1, tl, tm) ;
Node R = get(l ,r, v << 1 | 1, tm + 1, tr) ;
return combine(L, R) ;
}
Node get(int l, int r) {
if (l > r) return 0 ;
return get(l, r, 1, 1, _n) ;
}
};
int32_t main() {
ios::sync_with_stdio(false) ;
cin.tie(nullptr) ;
int n , m ; cin >> n >> m ;
vector<ll> a(n) ;
for (ll &i : a) cin >> i ;
vector<ll> b ;
for (int i = 0 ; i < n ; i++) {
ll cur = (i + 1) * m - a[i] ;
if (cur >= 0) {
b.push_back(cur) ;
}
}
auto calc = [&](vector<ll>& v) -> int {
vector<ll> c(v.begin(), v.end()) ;
sort(c.begin(), c.end()) ;
c.erase(unique(c.begin(), c.end()), c.end()) ;
auto get = [&](int i) -> int {
return (lower_bound(c.begin(), c.end(), i) - c.begin() + 1) ;
};
SegTree s(c.size() + 1) ;
vector<ll> dp(n, 1) ;
for (int i = 0 ; i < v.size() ; i++) {
dp[i] = max(dp[i], s.get(1, get(v[i])).value + 1) ;
s.modify(get(v[i]), dp[i]) ;
}
return *max_element(dp.begin(), dp.end()) ;
};
cout << n - calc(b) ;
return 0 ;
}
Compilation message
triusis.cpp: In lambda function:
triusis.cpp:75:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for (int i = 0 ; i < v.size() ; i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |