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 <stdio.h>
#define N 200000
int max(int a, int b) { return a > b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int aa[N];
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k) {
int c = aa[ii[j]] != aa[i_] ? aa[ii[j]] - aa[i_] : i_ - ii[j];
if (c == 0)
j++;
else if (c < 0) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
}
sort(ii, l, i);
l = k;
}
}
int ft[N];
void update(int i, int n, int x) {
while (i < n) {
ft[i] = max(ft[i], x);
i |= i + 1;
}
}
int query(int i) {
int x = 0;
while (i >= 0) {
x = max(x, ft[i]);
i &= i + 1, i--;
}
return x;
}
int main() {
static int ii[N];
int n, d, h, i;
scanf("%d%d", &n, &d);
for (i = 0; i < n; i++) {
scanf("%d", &aa[i]), aa[i] -= d * (i + 1);
ii[i] = i;
}
sort(ii, 0, n);
for (h = 0; h < n && aa[i = ii[h]] <= 0; h++)
update(n - 1 - i, n, query(n - 1 - i) + 1);
printf("%d\n", n - query(n - 1));
return 0;
}
Compilation message (stderr)
triusis.c: In function 'main':
triusis.c:60:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | scanf("%d%d", &n, &d);
| ^~~~~~~~~~~~~~~~~~~~~
triusis.c:62:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | scanf("%d", &aa[i]), aa[i] -= d * (i + 1);
| ^~~~~~~~~~~~~~~~~~~
# | 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... |