This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int inf = 1e8;
int a[maxn], dp[maxn];
int idx = 0;
int t[maxn * 4];
void update(int x, int val, int c = 1, int b = 1, int e = idx) {
if(b == e) {
t[c] = val;
return ;
}
int m = (b + e) >> 1;
int l = c << 1;
int r = l + 1;
if(x <= m) update(x, val, l, b, m);
else update(x, val, r, m + 1, e);
t[c] = max(t[l], t[r]);
}
int query(int x, int y, int c = 1, int b = 1, int e = idx) {
if(x <= b && e <= y) return t[c];
if(y < b || e < x) return -inf;
int m = (b + e) >> 1;
int l = c << 1;
int r = l + 1;
return max(query(x, y, l, b, m), query(x, y, r, m + 1, e));
}
int main() {
int n, k;
scanf("%d %d", &n, &k);
map <long long, int> comp;
comp[0] = 0;
for(int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
comp[1LL * k * i - a[i]] = 0;
}
for(auto &i : comp) {
i.second = ++idx;
}
for(int i = 1; i <= idx; i++) {
update(i, -inf);
}
update(comp[0], 0);
for(int i = 1; i <= n; i++) {
dp[i] = 1 + query(1, comp[1LL * k * i - a[i]]);
update(comp[1LL * k * i - a[i]], dp[i]);
}
cout << n - query(1, idx) << endl;
return 0;
}
Compilation message (stderr)
triusis.cpp: In function 'int main()':
triusis.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
32 | scanf("%d %d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~~
triusis.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
36 | scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |