#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 |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
1324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
1924 KB |
Output is correct |
2 |
Correct |
20 ms |
1704 KB |
Output is correct |
3 |
Correct |
27 ms |
1996 KB |
Output is correct |
4 |
Correct |
28 ms |
2000 KB |
Output is correct |
5 |
Correct |
33 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
318 ms |
18364 KB |
Output is correct |
2 |
Correct |
303 ms |
18344 KB |
Output is correct |
3 |
Correct |
292 ms |
18384 KB |
Output is correct |
4 |
Correct |
301 ms |
18344 KB |
Output is correct |
5 |
Correct |
283 ms |
17720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
275 ms |
17680 KB |
Output is correct |
2 |
Incorrect |
276 ms |
17780 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |