-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
56 lines (44 loc) · 1.2 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def solve():
n = int(input())
k = int(input())
a = list(map(int, input().split()))
mini = {}
maxi = {}
for i in range(n):
if a[i] not in mini or mini[a[i]] == 0:
mini[a[i]] = i + 1
else:
mini[a[i]] = min(mini[a[i]], i + 1)
if a[i] not in maxi or maxi[a[i]] == 0:
maxi[a[i]] = i + 1
else:
maxi[a[i]] = max(maxi[a[i]], i + 1)
v = []
for i in range(k, 0, -1):
if i not in mini or mini[i] == 0:
pass
elif i == k:
pass
else:
if i + 1 in mini and mini[i + 1] != 0:
maxi[i] = max(maxi[i], maxi[i + 1])
if i + 1 in mini and mini[i + 1] != 0:
mini[i] = min(mini[i], mini[i + 1])
if i in mini and mini[i] != 0:
v.append(2 * (maxi[i] - mini[i] + 1))
else:
if i != k:
maxi[i] = maxi[i + 1]
v.append(0)
if i != k:
mini[i] = mini[i + 1]
v.reverse()
for val in v:
print(val, end=" ")
print()
def main():
t = int(input())
for _ in range(t):
solve()
if __name__ == "__main__":
main()