#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--];
active[i_] = 1;
k++;
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 |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1168 KB |
Output is correct |
2 |
Correct |
11 ms |
1072 KB |
Output is correct |
3 |
Correct |
15 ms |
1108 KB |
Output is correct |
4 |
Correct |
12 ms |
1108 KB |
Output is correct |
5 |
Correct |
12 ms |
1072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
1108 KB |
Output is correct |
2 |
Correct |
20 ms |
1180 KB |
Output is correct |
3 |
Correct |
25 ms |
1048 KB |
Output is correct |
4 |
Correct |
26 ms |
1080 KB |
Output is correct |
5 |
Correct |
29 ms |
1140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
320 ms |
9028 KB |
Output is correct |
2 |
Correct |
295 ms |
8988 KB |
Output is correct |
3 |
Correct |
291 ms |
8988 KB |
Output is correct |
4 |
Correct |
322 ms |
9056 KB |
Output is correct |
5 |
Correct |
282 ms |
8992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
271 ms |
8988 KB |
Output is correct |
2 |
Correct |
283 ms |
8964 KB |
Output is correct |
3 |
Correct |
298 ms |
8968 KB |
Output is correct |
4 |
Correct |
136 ms |
9012 KB |
Output is correct |
5 |
Correct |
128 ms |
9036 KB |
Output is correct |