from collections import Counter
import sys as sus
input = sus.stdin.readline
n, m = map(int, input().split())
c = list(map(int, input().split()))
ct = Counter(c)
o = ct.most_common()
odd = Counter()
eve = Counter()
for i in range(n - 1):
s = min(c[i], c[i + 1])
b = max(c[i], c[i + 1])
if i % 2:
odd[(s << 20) | b] += 1
else:
eve[(s << 20) | b] += 1
out = []
for i in range(1, m + 1):
res = 0
for v, vc in o:
if v == i:
continue
bl = odd[i << 20 | v] + odd[v << 20 | i]
br = odd[v << 20 | i] + odd[i << 20 | v]
bad = min(bl, br)
res = max(res, vc - bad)
if bad == 0:
break
out.append(n - res - ct[i])
print('\n'.join(map(str, out)))
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
18592 KB |
Output is correct |
2 |
Correct |
40 ms |
18572 KB |
Output is correct |
3 |
Incorrect |
43 ms |
18584 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
18592 KB |
Output is correct |
2 |
Correct |
40 ms |
18572 KB |
Output is correct |
3 |
Incorrect |
43 ms |
18584 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
18592 KB |
Output is correct |
2 |
Correct |
40 ms |
18572 KB |
Output is correct |
3 |
Incorrect |
43 ms |
18584 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
18592 KB |
Output is correct |
2 |
Correct |
40 ms |
18572 KB |
Output is correct |
3 |
Incorrect |
43 ms |
18584 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
18592 KB |
Output is correct |
2 |
Correct |
40 ms |
18572 KB |
Output is correct |
3 |
Incorrect |
43 ms |
18584 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |