#include <stdio.h>
#define N 1000000
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)
if (aa[ii[j]] == aa[i_])
j++;
else if (aa[ii[j]] < aa[i_]) {
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 main() {
static int ii[N];
static char active[N];
int n, i, i_, j, k, k_, a;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
for (i = 0; i < n; i++)
ii[i] = i;
sort(ii, 0, n);
k = 0, k_ = 0;
for (j = n - 1; j >= 0; j = i) {
i = j, a = aa[ii[j]];
while (i >= 0 && aa[ii[i]] == a) {
i_ = ii[i--];
k++;
active[i_] = 1;
if (i_ > 0 && active[i_ - 1])
k--;
if (i_ + 1 < n && active[i_ + 1])
k--;
}
k_ = max(k_, k);
}
printf("%d\n", k_);
return 0;
}
Compilation message
gw.c: In function 'main':
gw.c:39:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
gw.c:41:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1168 KB |
Output is correct |
2 |
Correct |
12 ms |
1444 KB |
Output is correct |
3 |
Correct |
12 ms |
1352 KB |
Output is correct |
4 |
Correct |
12 ms |
1328 KB |
Output is correct |
5 |
Correct |
14 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
1100 KB |
Output is correct |
2 |
Correct |
19 ms |
1152 KB |
Output is correct |
3 |
Correct |
27 ms |
1072 KB |
Output is correct |
4 |
Correct |
26 ms |
1152 KB |
Output is correct |
5 |
Correct |
25 ms |
1104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
297 ms |
9052 KB |
Output is correct |
2 |
Correct |
307 ms |
8984 KB |
Output is correct |
3 |
Correct |
308 ms |
9064 KB |
Output is correct |
4 |
Correct |
297 ms |
8976 KB |
Output is correct |
5 |
Correct |
288 ms |
9100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
288 ms |
8992 KB |
Output is correct |
2 |
Correct |
295 ms |
9040 KB |
Output is correct |
3 |
Correct |
292 ms |
17676 KB |
Output is correct |
4 |
Correct |
128 ms |
11832 KB |
Output is correct |
5 |
Correct |
142 ms |
11832 KB |
Output is correct |