description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
n = int(input())
a = list(map(int, input().split()))
used = {}
x, y = [], []
for i in range(n):
if not used:
used[a[i]] = 1
x.append(i)
elif a[i] in used and used[a[i]] == 1:
y.append(i)
used = {}
else:
used[a[i]] = used.get(a[i], 0) + 1
if not y:
print(-1)
else:
if len(x) > len(y):
del x[-1]
y[-1] = n - 1
print(len(x))
for i in range(len(x)):
print(x[i] + 1, y[i] + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
slow, fast = 0, 0
cnt = {}
mx = -1
while fast < n:
x = a[fast]
cnt[x] = cnt.get(x, 0) + 1
if len(cnt) <= k and fast - slow > mx:
mx = fast - slow
l, r = slow + 1, fast + 1
elif len(cnt) > k:
x = a[slow]
cnt[x] -= 1
if cnt[x] == 0:
del cnt[x]
slow += 1
fast += 1
print(l, r)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
def good(nums):
for num in nums:
if nums[num] > 1:
return True
return False
n = int(input())
a = [int(i) for i in input().split()]
s = []
l, r = 0, 0
nums = {}
for i in range(n):
num = a[i]
if num in nums:
break
else:
nums[num] = True
else:
print(-1)
exit()
nums = {}
while r < n:
while r < n:
num = a[r]
if num in nums:
r += 1
break
else:
nums[num] = True
r += 1
r -= 1
s.append([l, r])
r += 1
l = r
nums = {}
length = len(s)
last = s[length - 1]
for i in range(last[0], last[1] + 1):
num = a[i]
if num in nums:
print(length)
break
else:
nums[num] = True
else:
s.pop()
s[length - 2][1] = n - 1
print(length - 1)
for st in s:
for c in st:
print(c + 1, end=" ")
print()
|
FUNC_DEF FOR VAR VAR IF VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR DICT WHILE VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
def main():
n, k = map(int, input().split())
myList = list(map(int, input().split()))
i = 0
distinct = 0
dictOf = [0] * 1000001
best = 0
bestX = 0
bestY = 0
for j in range(n):
dictOf[myList[j]] += 1
if dictOf[myList[j]] == 1:
distinct += 1
while distinct > k:
dictOf[myList[i]] -= 1
if dictOf[myList[i]] == 0:
distinct -= 1
i += 1
if j - i + 1 > best:
best = j - i + 1
bestX = i + 1
bestY = j + 1
print(bestX, bestY)
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
n = int(input())
A = [int(x) for x in input().split()]
s = {A[0]}
left = 1
segments = []
for i in range(1, n):
if A[i] in s:
segments.append((left, i + 1))
left = i + 2
s.clear()
else:
s.add(A[i])
if len(segments) == 0:
print(-1)
else:
segments[-1] = segments[-1][0], n
print(len(segments))
for l, r in segments:
print(l, r)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
n = int(input())
a = list(map(int, input().split()))
ans = []
s = set()
for i in range(len(a)):
if a[i] in s:
s = set()
ans.append(i + 1)
else:
s.add(a[i])
if len(ans) == 0:
print(-1)
elif len(ans) == 1:
print(len(ans))
print(1, len(a))
else:
print(len(ans))
for i in range(len(ans)):
if i == 0:
print(1, ans[0])
elif i == len(ans) - 1:
print(ans[i - 1] + 1, len(a))
else:
print(ans[i - 1] + 1, ans[i])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
s = input().split()
n, k = int(s[0]), int(s[1])
s = input().split()
a = []
for i in range(n):
e = int(s[i])
a.append(e)
freq, add = [], []
for i in range(10**6 + 1):
freq.append(0)
for i in range(n):
add.append(1)
i, j = 0, 0
d = 0
m = -1
l, r = -1, -1
while i <= j and j < n:
d += freq[a[j]] == 0
freq[a[j]] += add[j]
add[j] = 0
if d > k:
freq[a[i]] = max(0, freq[a[i]] - 1)
d -= freq[a[i]] == 0
i += 1
else:
temp = j - i
if temp > m:
m = temp
l, r = i + 1, j + 1
j += 1
print(l, r)
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
n = int(input())
s = input().split()
initial_pos = 0
ans = 0
ans_list = []
l = set()
for i in range(n):
if s[i] in l:
ans += 1
ans_list.append([initial_pos + 1, i + 1])
initial_pos = i + 1
l = set()
else:
l.add(s[i])
if ans == 0:
print(-1)
else:
if not ans_list[-1][1] == n:
ans_list[-1][1] = n
print(ans)
for i in ans_list:
print(" ".join(str(e) for e in i))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
from sys import stdin, stdout
n, k = [int(i) for i in stdin.readline().split()]
s = [0] * (10**6 + 1)
a = [int(i) for i in stdin.readline().split()]
mx = lmx = rmx = l = sm = 0
r = -1
while True:
r += 1
if r == n:
mx, lmx, rmx = max((mx, lmx, rmx), (r - l, l, r - 1))
break
if not s[a[r]]:
sm += 1
s[a[r]] += 1
if sm > k:
mx, lmx, rmx = max((mx, lmx, rmx), (r - l, l, r - 1))
while sm > k and l < r:
s[a[l]] -= 1
if not s[a[l]]:
sm -= 1
l += 1
elif r == n - 1:
mx, lmx, rmx = max((mx, lmx, rmx), (r - l + 1, l, r))
break
print(lmx + 1, rmx + 1)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
n = int(input())
cnt = 0
gems = list(map(int, input().split()))
pearls = set()
for i in range(n):
if gems[i] not in pearls:
pearls.add(gems[i])
else:
cnt += 1
pearls = set()
if cnt:
print(cnt)
first = 0
second = 0
pearls = set()
for i in range(n):
if gems[i] not in pearls:
pearls.add(gems[i])
else:
if second:
print(first + 1, second + 1)
first = second + 1
second = i
pearls = set()
print(first + 1, n)
else:
print("-1")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
n = int(input())
j = list(map(int, input().split()))
b = 0
e = 0
ans = []
subline = set()
while e < n:
perl = j[e]
if perl in subline:
ans += [[b + 1, e + 1]]
subline = set()
b = e + 1
e += 1
else:
subline.add(perl)
e += 1
if len(ans) == 0:
print(-1)
else:
ans[-1][1] = n
print(len(ans))
for i in range(len(ans)):
print(" ".join(list(map(str, ans[i]))))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR LIST LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
n = int(input())
a = [k for k in input().split(" ")]
answer = -1
l = []
dict = {}
i = 0
for j in range(len(a)):
if dict.get(a[j]):
dict = {}
answer += 1
l.append(i)
l.append(j)
i = j + 1
else:
dict.update({a[j]: 1})
if len(l) >= 1:
l[len(l) - 1] = n - 1
if answer == -1:
print(answer)
else:
print(int(answer + 1))
for p in l:
print(str(p + 1) + " ")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR DICT VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR DICT VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
def solve(n, k, a):
l, r, cur, answer_l, answer_r = 0, 0, 1, 0, 0
cnt = [(0) for _ in range(1000010)]
cnt[a[0]] = 1
while r + 1 < n:
r += 1
cnt[a[r]] += 1
if cnt[a[r]] == 1:
cur += 1
if cur > k:
if r - l - 1 > answer_r - answer_l:
answer_l, answer_r = l, r - 1
while cur > k:
cnt[a[l]] -= 1
if cnt[a[l]] == 0:
cur -= 1
l += 1
if r - l > answer_r - answer_l:
answer_l, answer_r = l, r
print(answer_l + 1, answer_r + 1)
def __starting_point():
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
solve(n, k, a)
__starting_point()
|
FUNC_DEF ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = set([])
c = []
d = 1
for i in range(n):
if a[i] in b:
b = set([])
c.append([d, i + 1])
d = i + 2
else:
b.add(a[i])
if len(c) == 0:
print(-1)
else:
c[-1][-1] = n
print(len(c))
for i in range(len(c)):
print(*c[i])
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
n = int(input())
a = list(map(int, input().split()))
z = []
p = set()
k1 = 1
for i in range(n):
if a[i] in p:
z.append((k1, i + 1))
k1 = i + 2
p = set()
else:
p.add(a[i])
if len(z) > 0:
z[len(z) - 1] = z[len(z) - 1][0], n
print(len(z))
for k in z:
print(k[0], k[1])
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
def longest(n, k, a):
f = [0] * 1000001
d = 0
r = 0
l = 0
ans_l = 0
ans_r = 0
for r in range(0, n):
f[a[r]] += 1
if f[a[r]] == 1:
d += 1
while d > k:
f[a[l]] -= 1
if f[a[l]] == 0:
d -= 1
l += 1
if ans_r - ans_l < r - l:
ans_r = r
ans_l = l
return str(ans_l + 1) + " " + str(ans_r + 1)
line_1 = list(map(int, input().split()))
n = line_1[0]
k = line_1[1]
line_2 = list(map(int, input().split()))
print(longest(n, k, line_2))
|
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
import sys
sys.setrecursionlimit(10**6)
def get_array():
return list(map(int, sys.stdin.readline().split()))
def get_ints():
return map(int, sys.stdin.readline().split())
def input():
return sys.stdin.readline().strip("\n")
n = int(input())
l = get_array()
n = len(l)
ans = []
i, j = 0, 0
while i < n:
s = set()
while j < n and l[j] not in s:
s.add(l[j])
j += 1
if j == n:
break
ans.append([i, j])
j += 1
i = j
if len(ans) == 0:
print(-1)
else:
print(len(ans))
ans[-1][-1] = max(n - 1, ans[-1][-1])
for i in ans:
print(i[0] + 1, i[1] + 1)
|
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
n = int(input())
d = {}
arr = []
p = list(map(int, input().split()))
l = 0
for i in range(n):
try:
d[p[i]] += 1
arr.append([l + 1, i + 1])
l = i + 1
d = {}
except:
d[p[i]] = 1
if len(arr) != 0:
arr[-1][1] = max(arr[-1][1], n)
if len(arr) == 0:
print(-1)
else:
print(len(arr))
for i in range(len(arr)):
print(arr[i][0], arr[i][1])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
import sys
n = int(input())
a = list(map(int, input().split()))
left = set()
i = 1
ans = []
for j, x in enumerate(a, start=1):
if x in left:
ans.append([i, j])
left.clear()
i = j + 1
else:
left.add(x)
if not ans:
print(-1)
else:
ans[-1][1] = n
s = str(len(ans)) + "\n" + "\n".join(" ".join((str(x), str(y))) for x, y in ans)
sys.stdout.buffer.write(s.encode("utf-8"))
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
num = int(input())
types = input().split()
if num != len(types):
print(-1)
else:
myseg = []
myindex = []
myset = set()
mystr = []
for i in range(num):
if len(myseg) == 0:
myseg.append(types[i])
myset.add(types[i])
mystr.append(str(i + 1))
elif types[i] in myset:
myseg.append(types[i])
mystr.append(str(i + 1))
myindex.append(mystr[0] + " " + mystr[1])
myseg.clear()
myset.clear()
mystr.clear()
else:
myseg.append(types[i])
myset.add(types[i])
if len(myseg) != 0:
if len(myindex) == 0:
print(-1)
else:
oldstr = myindex[-1].split()
newstr = oldstr[0] + " " + str(num)
myindex[-1] = newstr
print(len(myindex))
for x in myindex:
print(x)
else:
print(len(myindex))
for x in myindex:
print(x)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
l, r = 0, 0
hsh = [0] * 1000005
idx = [1, 1]
hsh[a[0]] = 1
cnt, ans = 1, -1
while r < n - 1 and l <= r:
if hsh[a[r + 1]] == 0 and cnt < k:
r += 1
hsh[a[r]] += 1
cnt += 1
if r - l > ans:
idx = [l + 1, r + 1]
ans = r - l
elif hsh[a[r + 1]] == 0 and cnt == k:
while cnt == k:
if hsh[a[l]] == 1:
cnt -= 1
hsh[a[l]] -= 1
l += 1
break
else:
hsh[a[l]] -= 1
l += 1
r += 1
hsh[a[r]] += 1
cnt += 1
if r - l > ans:
idx = [l + 1, r + 1]
ans = r - l
elif hsh[a[r + 1]] != 0:
r += 1
hsh[a[r]] += 1
if r - l > ans:
idx = [l + 1, r + 1]
ans = r - l
print(*idx)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR WHILE VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
n = int(input())
data = list(map(int, input().split()))
answer = []
start = 1
finish = 1
help_set = set()
for i in range(n):
if data[i] in help_set:
answer.append([start, finish])
help_set = set()
start = finish + 1
finish += 1
else:
finish += 1
help_set.add(data[i])
if len(answer) == 0:
print(-1)
elif n == 1:
print(1)
print(1, 1)
else:
answer[-1][-1] = n
print(len(answer))
for i in range(len(answer)):
print(*answer[i])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
n = int(input())
a = map(int, input().split())
st = 1
cnt = set()
answer = []
for i, x in enumerate(a):
if x in cnt:
en = i + 1
answer.append([st, en])
cnt = set()
st = i + 2
else:
cnt.add(x)
if len(answer) == 0:
print(-1)
else:
print(len(answer))
answer[-1][1] = n
for x in answer:
print(x[0], x[1])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
R = lambda: map(int, input().split())
n, k = R()
arr = list(R())
rl, rr = 0, 0
l = 0
rec = {}
for r, v in enumerate(arr):
rec.setdefault(v, 0)
rec[v] += 1
while len(rec) > k:
rec[arr[l]] -= 1
if not rec[arr[l]]:
rec.pop(arr[l])
l += 1
if rr - rl < r - l:
rl, rr = l, r
print(rl + 1, rr + 1)
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
from sys import exit, stdin, stdout
n = int(stdin.readline())
a = [int(i) for i in stdin.readline().split()]
ans = []
s = set()
i = 0
j = -1
while True:
j += 1
if j == n:
if len(ans) != 0:
ans[-1] = ans[-1][0], j - 1
break
if a[j] in s:
s = set()
ans.append((i, j))
i = j + 1
j = i - 1
else:
s.add(a[j])
if len(ans) == 0:
print(-1)
exit(0)
stdout.write(str(len(ans)) + "\n")
for x, y in ans:
stdout.write(str(x + 1) + " " + str(y + 1) + "\n")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER IF VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
from sys import stdin
n = int(stdin.buffer.readline())
a = list(map(int, stdin.buffer.readline().split()))
mp = dict()
l = 0
res = list()
for i in range(n):
if a[i] in mp:
res.append((l + 1, i + 1))
mp.clear()
l = i + 1
else:
mp[a[i]] = 1
if len(res) == 0:
print(-1)
exit()
print(len(res))
for i in range(len(res)):
if i == len(res) - 1:
print(res[i][0], n)
else:
print(res[i][0], res[i][1])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
n = int(input())
ar = list(map(int, input().split()))
s = set()
ans = []
p = 1
for i in range(len(ar)):
if ar[i] not in s:
s.add(ar[i])
else:
ans.append([p, i + 1])
p = i + 2
s.clear()
if len(ans) != 0 and len(s):
ans[-1] = [ans[-1][0], len(ar)]
if len(ans):
print(len(ans))
for i in ans:
print(i[0], i[1])
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER LIST VAR NUMBER NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
if len(set(A)) == N:
print(-1)
else:
S = set()
res = []
lt = 1
for i in range(N):
if A[i] in S:
res.append([lt, i + 1])
S = set()
lt = i + 2
else:
S.add(A[i])
res[-1][-1] = N
print(len(res))
for i in range(len(res)):
res[i] = " ".join(map(str, res[i]))
print("\n".join(map(str, res)))
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
import sys
count = int(input())
perls = list(input().split(" "))
if len(perls) < 2:
print("-1")
sys, exit()
start = 0
cur = 0
flag = 0
slide = set()
goodlist = list()
for i in perls:
if i in slide:
goodlist.append([start + 1, cur + 1])
start = cur + 1
slide.clear()
flag = 1
else:
slide.add(i)
flag = 0
cur += 1
if len(goodlist) == 0:
print("-1")
sys.exit()
if flag == 0:
goodlist[-1][1] = len(perls)
print(len(goodlist))
for i in goodlist:
print("{} {}".format(i[0], i[1]))
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR NUMBER
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
n = int(input())
t = list(map(int, input().split()))
f = {}
l = []
st = 1
for j in range(n):
if t[j] not in f:
f[t[j]] = 1
else:
l.append([st, j + 1])
f = {}
st = j + 2
if st != n + 1:
if len(l) > 0:
a = l.pop()[0]
l.append([a, n])
print(len(l))
for j in l:
print(*j)
else:
print(-1)
else:
print(len(l))
for j in l:
print(*j)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
n = int(input())
ans = list()
s = set()
for i, x in enumerate(map(int, input().split())):
if not s:
idx = i + 1
elif x in s:
ans.append((idx, i + 1))
s = set()
continue
s.add(x)
if len(ans):
ans[-1] = ans[-1][0], n
print(len(ans))
print("\n".join("%d %d" % p for p in ans))
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP STRING VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
n = int(input())
arr = [int(x) for x in input().split()]
v = {}
ans = []
prev = 0
for i in range(n):
if arr[i] in v:
ans.append([prev + 1, i + 1])
v = {}
prev = i + 1
else:
v[arr[i]] = i
if ans:
ans[-1][1] = n
print(len(ans))
for i in ans:
print(i[0], i[1])
else:
print("-1")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR ASSIGN VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
n = int(input())
a = [int(x) for x in input().split()]
r = []
s = set()
l = 0
for i, x in enumerate(a):
if x in s:
r.append([l + 1, i + 1])
l = i + 1
s = set()
else:
s.add(x)
if l == 0:
print(-1)
else:
if s:
r[-1][1] = n
print(len(r))
print("\n".join("{0} {1}".format(p, q) for p, q in r))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR ASSIGN VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING VAR VAR VAR VAR VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
def main():
n, k = map(int, input().split())
l, cnt = list(map(int, input().split())), [0] * 1000001
start = end = j = m = 0
for i, x in enumerate(l):
if not cnt[x]:
k -= 1
cnt[x] += 1
if k < 0:
x = l[j]
cnt[x] -= 1
if not cnt[x]:
k += 1
j += 1
if m < i - j:
m, start, end = i - j, j, i
print(start + 1, end + 1)
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
def main():
n, res = int(input()), []
s, i, fmt = set(), 1, "{:n} {:n}".format
for j, a in enumerate(input().split(), 1):
if a in s:
s = set()
res.append(fmt(i, j))
i = j + 1
else:
s.add(a)
if res:
print(len(res))
res[-1] = res[-1].split()[0] + " " + str(n)
print("\n".join(res))
else:
print(-1)
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR LIST ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER STRING FOR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR NUMBER NUMBER STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
import sys
n = int(input())
a = list(map(int, input().split()))
ans = []
sa = sorted(a)
cmpr = {}
for i in range(0, len(a)):
cmpr[sa[i]] = i
cid = [(0) for i in range(0, n)]
id = 1
pi = 0
for i in range(0, n):
if cid[cmpr[a[i]]] == id:
ans.append(i + 1)
id += 1
continue
cid[cmpr[a[i]]] = id
if len(ans) == 0:
print(-1)
else:
ans[-1] = n
print(len(ans))
ans = [0] + ans
for i in range(0, len(ans) - 1):
print(ans[i] + 1, ans[i + 1])
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
n = int(input())
lis = [*map(int, input().split())]
ans = []
k = 0
s = set()
for i in range(n):
if lis[i] in s:
ans.append([k + 1, i + 1])
k = i + 1
s = set()
else:
s.add(lis[i])
c = len(ans)
if c == 0:
print("-1")
else:
print(c)
ans[-1][1] = n
for i in ans:
print(*i)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
R = lambda: map(int, input().split())
n = int(input())
a = list(R())
s = set()
l = 0
r = []
for i in range(0, len(a)):
if a[i] in s:
r.append((l + 1, i + 1))
s = set()
l = i + 1
else:
s.add(a[i])
if len(s) == 0:
print(len(r))
for p in r:
print(*p)
elif len(r) > 0:
print(len(r))
r[len(r) - 1] = r[len(r) - 1][0], n
for p in r:
print(*p)
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == n:
print(-1)
else:
ls = []
b = set()
l = 1
b.add(a[0])
for i in range(1, n):
if a[i] not in b:
b.add(a[i])
else:
ls.append([l, i + 1])
l = i + 2
b = set()
if ls[-1][1] != n:
ls[-1][1] = n
print(len(ls))
for i in range(len(ls)):
print(*ls[i])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
-----Input-----
The first line contains two integers n, k (1 β€ k β€ n β€ 5Β·10^5) β the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
Print two integers l, r (1 β€ l β€ r β€ n) β the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.
-----Examples-----
Input
5 5
1 2 3 4 5
Output
1 5
Input
9 3
6 5 1 2 3 2 1 4 5
Output
3 7
Input
3 1
1 2 3
Output
1 1
|
length = int(input())
gems = input().split()
result = []
s = 0
dist = set()
pend_e = 0
pend_s = 0
for i in range(0, length):
cur = gems[i]
if cur not in dist:
dist.add(cur)
else:
if pend_e != 0:
result.append([pend_s, pend_e])
pend_e = i + 1
pend_s = s + 1
s = i + 1
dist.clear()
if s != 0 and pend_e != length + 1:
result.append([pend_s, length])
if len(result) == 0:
print(-1)
else:
print(len(result))
for r in result:
print(r[0], r[1])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
maxn = 300000.0 + 5
def solve(arr, n):
f = [0] * (n + 1)
last = [0] * (n + 1)
ans = [-1] * (n + 1)
for i in range(1, n + 1):
x = arr[i]
f[x] = max(f[x], i - last[x])
last[x] = i
for x in range(1, n + 1):
f[x] = max(f[x], n - last[x] + 1)
i = f[x]
while i <= n and ans[i] == -1:
ans[i] = x
i += 1
print(*ans[1:])
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
arr = [0] + arr
solve(arr, n)
|
ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
last = [(-1) for _ in range(n)]
maxlen = [(-1) for _ in range(n)]
for i in range(n):
x = a[i] - 1
maxlen[x] = max(maxlen[x], i - last[x])
last[x] = i
maxlen = [max(maxlen[i], n - last[i]) for i in range(n)]
sol = [(-1) for _ in range(n + 2)]
for i in range(n):
if sol[maxlen[i]] == -1:
sol[maxlen[i]] = i + 1
sol = sol[1 : len(sol) - 1]
if sol[0] == -1:
sol[0] = n + 2
for i in range(1, n):
if sol[i] == -1:
sol[i] = n + 2
sol[i] = min(sol[i], sol[i - 1])
for i in range(n):
if sol[i] == n + 2:
sol[i] = -1
else:
break
print(" ".join([str(i) for i in sol]))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
import sys
input = sys.stdin.readline
INF = 10**6
t = int(input())
for _ in range(t):
n = int(input())
a = [int(item) for item in input().split()]
last_found = [-1] * (n + 1)
holes = [0] * (n + 1)
hole_size = [INF] * (n + 1)
for i, val in enumerate(a):
holes[val] = max(holes[val], i - last_found[val] - 1)
last_found[val] = i
for val in range(1, n + 1):
holes[val] = max(holes[val], n - last_found[val] - 1)
for i, item in enumerate(holes):
if i == 0:
continue
if hole_size[item] != INF:
continue
else:
hole_size[item] = i
ans = INF
ret = []
for i in range(n):
ans = min(ans, hole_size[i])
if ans == INF:
ret.append(-1)
else:
ret.append(ans)
print(*ret)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
fullans = ""
for _ in range(int(input())):
n = int(input())
ls = list(map(int, input().split()))
ar = [[] for i in range(n)]
ans = [None] * n
for i in range(n):
ar[ls[i] - 1].append(i)
for j in range(n):
if len(ar[j]) == 0:
continue
mn = ar[j][0]
for i in range(1, len(ar[j])):
mn = max(ar[j][i] - ar[j][i - 1] - 1, mn)
mn = max(n - 1 - ar[j][-1], mn)
if ans[mn] is None:
ans[mn] = j + 1
curr = -1
for i in range(n):
if ans[i] is None:
ans[i] = curr
elif curr == -1:
curr = ans[i]
else:
curr = min(ans[i], curr)
ans[i] = curr
for i in ans:
print(i, end=" ")
print()
|
ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR IF VAR VAR NONE ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NONE ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
import sys
input = sys.stdin.readline
for i in " " * int(input()):
n = int(input())
L = list(map(int, input().split()))
L1 = [0] * n
L2 = [-1] * n
for i in range(n):
k = L[i]
L1[k - 1] = max(L1[k - 1], i - L2[k - 1])
L2[k - 1] = i
for i in range(n):
k = L[i]
L1[k - 1] = max(L1[k - 1], n - L2[k - 1])
checkL = [-1] * n
for i in range(n):
if checkL[L1[i] - 1] == -1 and L1[i] != 0:
checkL[L1[i] - 1] = i + 1
rem = -1
for i in range(n):
if checkL[i] == -1:
print(rem, end=" ")
else:
if rem != -1 and rem < checkL[i]:
print(rem, end=" ")
continue
print(checkL[i], end=" ")
rem = checkL[i]
print()
|
IMPORT ASSIGN VAR VAR FOR VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING IF VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
from sys import stdin
for _ in range(int(input())):
n = int(input())
a = [int(i) for i in stdin.readline().split()]
prev = [-1] * (n + 1)
dist = [0] * (n + 1)
mi = n
prev[a[0]] = 0
for i in range(n):
temp = i - prev[a[i]]
prev[a[i]] = i
dist[a[i]] = max(dist[a[i]], temp)
prev = [n] * (n + 1)
prev[a[n - 1]] = n - 1
for i in range(n - 1, -1, -1):
temp = prev[a[i]] - i
prev[a[i]] = i
dist[a[i]] = max(dist[a[i]], temp)
ans = [-1] * n
for i in range(1, n + 1):
if ans[dist[i] - 1] == -1 and dist[i] != 0:
ans[dist[i] - 1] = i
mini = -1
for i in range(n):
if ans[i] != -1:
if mini != -1:
mini = min(mini, ans[i])
ans[i] = min(mini, ans[i])
else:
mini = ans[i]
elif mini != -1 and ans[i] == -1:
ans[i] = mini
print(*ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
import sys
input = sys.stdin.readline
def solve():
n = int(input())
a = list(map(int, input().split()))
d = {}
for i, v in enumerate(a):
if v in d:
d[v]["max"] = max(d[v]["max"], i - d[v]["pos"])
d[v]["pos"] = i
else:
d[v] = {"max": i + 1, "pos": i}
for v in d:
d[v]["max"] = max(d[v]["max"], n - d[v]["pos"])
ans = {}
for v in d:
m = d[v]["max"]
if m in ans:
if v < ans[m]:
ans[m] = v
else:
ans[m] = v
prev = -1
for i in range(1, n + 1):
cur = ans.get(i, -1)
if cur == -1:
res = prev
elif prev == -1:
res = cur
else:
res = min(cur, prev)
prev = res
print(res, end=" ")
print()
t = int(input())
for _ in range(t):
solve()
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR STRING FUNC_CALL VAR VAR VAR STRING BIN_OP VAR VAR VAR STRING ASSIGN VAR VAR STRING VAR ASSIGN VAR VAR DICT STRING STRING BIN_OP VAR NUMBER VAR FOR VAR VAR ASSIGN VAR VAR STRING FUNC_CALL VAR VAR VAR STRING BIN_OP VAR VAR VAR STRING ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR VAR STRING IF VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
for h in range(int(input())):
n = int(input())
arr = list(map(int, input().strip().split()))
dicti = {i: float("inf") for i in range(1, n)}
last_occ = {}
for i in range(n):
if arr[i] not in last_occ:
dicti[arr[i]] = i + 1
last_occ[arr[i]] = i
else:
dicti[arr[i]] = max(i - last_occ[arr[i]], dicti[arr[i]])
last_occ[arr[i]] = i
for i in last_occ:
dicti[i] = max(dicti[i], n - last_occ[i])
win_s = {}
for i in dicti:
if dicti[i] not in win_s:
win_s[dicti[i]] = i
else:
win_s[dicti[i]] = min(i, win_s[dicti[i]])
ans = []
mini = float("inf")
for i in range(1, n + 1):
if i in win_s:
mini = min(mini, win_s[i])
ans.append(mini)
elif mini != float("inf"):
ans.append(mini)
else:
ans.append(-1)
print(*ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
t = int(input())
for tt in range(t):
n = int(input())
a = list(map(int, input().split()))
pre = {}
gap = {}
for i, ai in enumerate(a):
if ai in pre:
gap[ai] = max(gap[ai], i - pre[ai] - 1)
else:
gap[ai] = i
pre[ai] = i
for ai in pre:
gap[ai] = max(gap[ai], n - pre[ai] - 1)
ans = [(gap[ai], ai) for ai in gap]
ans.sort()
p = 0
cur = int(1000000000.0)
for i in range(n):
while p < len(ans) and ans[p][0] <= i:
cur = min(cur, ans[p][1])
p += 1
print(-1 if cur == int(1000000000.0) else cur, end="")
print(end=" " if i != n - 1 else "")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER NUMBER VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING STRING EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
def Work():
global n, arr, f, last, ans
n = int(input())
arr = [0] * (n + 1)
arr[1:] = list(map(int, input().split()))
f = [0] * (n + 1)
ans = [-1] * (n + 1)
last = [0] * (n + 1)
for i in range(1, n + 1):
f[arr[i]] = max(f[arr[i]], i - last[arr[i]])
last[arr[i]] = i
for x in range(1, n + 1):
f[x] = max(f[x], n - last[x] + 1)
i = f[x]
while i <= n and ans[i] == -1:
ans[i] = x
i += 1
for e in range(1, n + 1):
print(ans[e], end=" ")
print()
t = int(input())
for _ in range(t):
Work()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
import sys
input = sys.stdin.readline
I = lambda: list(map(int, input().split()))
(t,) = I()
for _ in range(t):
(n,) = I()
l = I()
r = [[] for i in range(n + 1)]
for i in range(n):
r[l[i]].append(i)
an = [-1] * (n + 1)
for i in range(n, 0, -1):
if r[i]:
cr = [-1] + r[i]
pr = n
x = 0
for j in range(len(cr) - 1, -1, -1):
x = max(x, pr - cr[j])
pr = cr[j]
an[x] = i
for i in range(1, n):
if an[i] != -1:
if an[i + 1] == -1 or an[i + 1] > an[i]:
an[i + 1] = an[i]
print(*an[1:])
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
import sys
from _collections import deque
input = lambda: sys.stdin.readline().rstrip("\r\n")
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
d = {}
v = {}
ans = deque([])
for it, i in enumerate(a):
d[i] = d.get(i, [0])
d[i].append(it + 1)
v[i] = max(d[i][-1] - d[i][-2], v.get(i, it + 1))
for i in v:
v[i] = max(v[i], n - d[i][-1] + 1)
for i in sorted(v):
if v[i] <= n:
while n >= v[i]:
ans.appendleft(i)
n -= 1
if not n:
break
if n:
while n >= 1:
ans.appendleft(-1)
n -= 1
print(*ans)
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR LIST NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR WHILE VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR IF VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
def cal(arr):
return max(arr[i] - arr[i - 1] for i in range(1, len(arr)))
for i in range(int(input())):
n = int(input())
arr = [int(i) for i in input().split()]
dic = {}
for i in range(len(arr)):
if arr[i] in dic:
dic[arr[i]].append(i + 1)
else:
dic[arr[i]] = [0, i + 1]
for i in dic:
dic[i].append(len(arr) + 1)
ans = [10**9] * len(arr)
for i in dic:
temp = cal(dic[i])
ans[temp - 1] = min(ans[temp - 1], i)
for i in range(1, len(ans)):
ans[i] = min(ans[i], ans[i - 1])
for i in range(0, len(ans)):
if ans[i] == 10**9:
ans[i] = -1
print(*ans)
|
FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
rw = int(input())
for wewq in range(rw):
n = int(input())
a = list(map(int, input().split()))
k = -1
c = 0
da = [[c, -1] for i in range(max(a) + 1)]
for i in range(n):
da[a[i]][0] = max(i - da[a[i]][1], da[a[i]][0])
da[a[i]][1] = i
for i in range(max(a) + 1):
da[i][0] = max(n - da[i][1], da[i][0])
da[i][1] = n
d = [0] * (max(a) + 1)
for i in range(max(a) + 1):
d[i] = da[i][0]
c = 10**9
lol = [c] * (n + 2)
for i in range(1, max(a) + 1):
if lol[d[i]] == c:
lol[d[i]] = i
mp = c
ll = []
for i in range(n + 1):
mp = min(lol[i], mp)
ll.append(mp)
for i in range(1, n + 1):
if ll[i] == c:
print(-1, end=" ")
else:
print(ll[i], end=" ")
print("")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
INF = 10**15
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
d = {i: (0) for i in arr}
last = {i: (-1) for i in arr}
for i in range(n):
if last[arr[i]] == -1:
d[arr[i]] = max(d[arr[i]], i + 1)
else:
d[arr[i]] = max(d[arr[i]], i - last[arr[i]])
last[arr[i]] = i
for i in last.keys():
d[i] = max(d[i], n - last[i])
d2 = {}
for k, v in d.items():
if v not in d2:
d2[v] = INF
d2[v] = min(d2[v], k)
ans = [INF] * n
for i in range(1, n + 1):
can = INF
if i != 1:
can = ans[i - 2]
if i in d2.keys():
can = min(can, d2[i])
ans[i - 1] = can
for i in range(n):
if ans[i] == INF:
ans[i] = -1
print(*ans)
|
ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
d = dict()
for i in range(n):
if arr[i] in d:
d[arr[i]].append(i + 1)
else:
d[arr[i]] = [i + 1]
d = sorted(d.items(), key=lambda x: x[0])
ans = [-1] * (n + 1)
for i in d:
last = 0
maxx = 0
for j in i[1]:
maxx = max(maxx, j - last)
last = j
ii = max(maxx, n - last + 1)
while ii <= n and ans[ii] == -1:
ans[ii] = i[0]
ii += 1
print(*ans[1:])
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR LIST BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
INF = 10**9
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
vals = [[-1] for i in range(n + 1)]
for i, val in enumerate(a):
vals[val].append(i)
ans = [INF] * (n + 1)
for val, tmp in enumerate(vals):
length = 0
tmp.append(n)
if len(tmp) == 2:
continue
for i in range(len(tmp) - 1):
length = max(tmp[i + 1] - tmp[i], length)
if length == 0:
continue
ans[length] = min(val, ans[length])
for i in range(n):
ans[i + 1] = min(ans[i], ans[i + 1])
if ans[i] == INF:
ans[i] = -1
print(*ans[1:])
|
ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
def dif_maker(q):
x = []
for i in range(len(q) - 1):
x.append(q[i + 1] - q[i])
return max(x)
for ad in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
ans = [-1] * n
y = []
for i in range(n + 1):
y.append([-1])
for i in range(n):
y[l[i]].append(i)
for i in range(n + 1):
y[i].append(n)
a = []
for i in y:
a.append(dif_maker(i))
c = n + 1
z = []
for i in range(n + 1):
x = a[i]
if c > x:
z += [i] * (c - x)
c = x
ans = z + [-1] * (n - len(z))
ans.reverse()
for i in ans:
print(i, end=" ")
print()
|
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR BIN_OP LIST VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP LIST NUMBER BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
def solve(n, ar):
pos = [[] for _ in range(n + 1)]
ans = [n + 1] * (n + 1)
for i in range(n):
pos[ar[i]].append(i + 1)
for i in range(1, n + 1):
mxgap = -1
if len(pos[i]) == 0:
continue
for j in range(len(pos[i])):
if j == 0:
mxgap = max(mxgap, pos[i][j] - 1)
if j == len(pos[i]) - 1:
mxgap = max(mxgap, n - pos[i][j])
if j - 1 >= 0:
mxgap = max(mxgap, pos[i][j] - pos[i][j - 1] - 1)
ans[mxgap + 1] = min(ans[mxgap + 1], i)
track = []
mini = n + 1
for i in range(1, n + 1):
mini = min(mini, ans[i])
if mini == n + 1:
track.append(-1)
else:
track.append(mini)
print(" ".join(map(str, track)))
t = int(input())
for _ in range(t):
n = int(input())
ar = list(map(int, input().split()))
solve(n, ar)
|
FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
def solve():
N = int(input())
As = list(map(int, input().split()))
last = [-1] * (N + 1)
dist = [-1] * (N + 1)
for i, A in enumerate(As):
dist[A] = max(dist[A], i - last[A])
last[A] = i
for A in range(N + 1):
dist[A] = max(dist[A], N - last[A])
answer = [10**9] * (N + 1)
for k, d in enumerate(dist):
if d > N:
continue
answer[d] = min(answer[d], k)
for i in range(N):
answer[i + 1] = min(answer[i], answer[i + 1])
for i in range(N + 1):
if answer[i] == 10**9:
answer[i] = -1
print(*answer[1:])
T = int(input())
for _ in range(T):
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
n = int(input())
A = list(map(int, input().split()))
STEP = [[] for i in range(n + 1)]
for i in range(n):
STEP[A[i]].append(i)
ANS = [1 << 60] * (n + 3)
for i in range(n + 1):
NOW = -1
MAX = -1
for k in STEP[i]:
MAX = max(MAX, k - NOW)
NOW = k
MAX = max(MAX, n - NOW)
ANS[MAX] = min(ANS[MAX], i)
ANSL = []
for i in range(1, n + 1):
ANS[i] = min(ANS[i], ANS[i - 1])
if ANS[i] == 1 << 60:
ANSL.append(-1)
else:
ANSL.append(ANS[i])
print(*ANSL)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
import sys
def input():
return sys.stdin.readline().rstrip()
t = int(input())
for i in range(t):
n = int(input())
ans = [-1] * (n + 1)
arr = list(map(int, input().split()))
val_with_index = []
for i in range(0, n):
val_with_index.append((arr[i], i))
val_with_index.sort()
positions = []
for i in range(0, n):
positions.append(val_with_index[i][1])
if i == n - 1 or i + 1 < n and val_with_index[i][0] != val_with_index[i + 1][0]:
positions.append(n)
max_of_min_segment_len = positions[0] + 1
for j in range(1, len(positions)):
max_of_min_segment_len = max(
max_of_min_segment_len, positions[j] - positions[j - 1]
)
for k in range(max_of_min_segment_len, n + 1):
if ans[k] == -1:
ans[k] = val_with_index[i][0]
else:
break
positions = []
print(" ".join(map(str, ans[1:])))
|
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
l = [[-1] for i in range(n)]
ans = []
cursz = n
for i in range(n):
l[a[i] - 1].append(i)
for i in range(n):
if cursz == 0 or len(ans) == n:
break
mxdiff = -1
if len(l[i]) == 1:
continue
else:
l[i].append(n)
for j in range(len(l[i]) - 1):
mxdiff = max(mxdiff, l[i][j + 1] - l[i][j])
if mxdiff <= cursz:
for j in range(cursz - mxdiff + 1):
ans.append(i + 1)
cursz = mxdiff - 1
for i in range(n - len(ans)):
print(-1, end=" ")
for i in range(len(ans) - 1, -1, -1):
print(ans[i], end=" ")
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
def main():
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
block = [(0, 0, 0)] * (n + 1)
for i in range(n):
x, y, z = block[a[i]]
if y == 0:
x = i + 1
else:
x = max(x, i + 1 - y)
y = i + 1
z = i + 1
block[a[i]] = x, y, z
ans = [-1] * (n + 1)
for x in range(1, n + 1):
m = max(block[x][0], n - block[x][2] + 1)
if not m:
continue
for i in range(m, n + 1):
if ans[i] == -1:
ans[i] = x
else:
break
print(*ans[1:])
main()
|
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
import sys
sys.setrecursionlimit(10**5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def SI():
return sys.stdin.readline()[:-1]
inf = 10**9
for _ in range(II()):
n = II()
aa = LI()
mx = n + 5
ww = [-1] * mx
pos = [-1] * mx
for i, a in enumerate(aa):
ww[a] = max(ww[a], i - pos[a])
pos[a] = i
for a in range(mx):
if pos[a] == -1:
continue
ww[a] = max(ww[a], n - pos[a])
ktoa = [inf] * (n + 1)
for a in range(mx):
if ww[a] == -1:
continue
ktoa[ww[a]] = min(ktoa[ww[a]], a)
mn = inf
ans = []
for k in range(1, n + 1):
mn = min(mn, ktoa[k])
if mn == inf:
ans.append(-1)
else:
ans.append(mn)
print(*ans)
|
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
t = int(input())
for _ in range(t):
n = int(input())
arr = [int(p) for p in input().split()]
period = [-1] * (max(arr) + 7)
index = [-1] * (max(arr) + 7)
for i in range(len(arr)):
period[arr[i]] = max(period[arr[i]], i - index[arr[i]])
index[arr[i]] = i
for i in range(len(period)):
period[i] = max(period[i], n - index[i])
final = {}
for i in range(len(period)):
if period[i] in final:
final[period[i]] = min(final[period[i]], i)
else:
final[period[i]] = i
ans = [float("inf")] * n
for i in range(n):
if i + 1 in final:
ans[i] = final[i + 1]
curr = float("inf")
for i in range(len(ans)):
if ans[i] == float("inf"):
if curr == float("inf"):
ans[i] = -1
else:
ans[i] = curr
else:
curr = min(curr, ans[i])
ans[i] = curr
print(*ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
t = int(input())
while t > 0:
t -= 1
n = int(input())
arr = [int(x) for x in input().split()]
ans = [float("inf") for x in range(n)]
hmap = {}
hm = {}
for i in range(n):
if hmap.get(arr[i]) is None:
hmap[arr[i]] = i
hm[arr[i]] = i
else:
hm[arr[i]] = max(i - hmap[arr[i]] - 1, hm[arr[i]])
hmap[arr[i]] = i
for h in hm:
hm[h] = max(n - hmap[h] - 1, hm[h])
ans[hm[h]] = min(h, ans[hm[h]])
mn = ans[0]
for i in range(n):
mn = min(mn, ans[i])
ans[i] = min(mn, ans[i])
for i in range(n):
if ans[i] == float("inf"):
ans[i] = -1
print(ans[i], end=" ")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NONE ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
for i in range(int(input())):
n = int(input())
a = [int(i) for i in input().split()]
db = {}
for i in range(n):
if a[i] not in db:
db[a[i]] = [0, i + 1]
else:
db[a[i]].append(i + 1)
for k in db.keys():
db[k].append(n + 1)
gaps = {}
for k, l in db.items():
dif = 0
for i in range(len(l) - 1):
dif = max(l[i + 1] - l[i], dif)
if dif not in gaps:
gaps[dif] = k
else:
gaps[dif] = min(k, gaps[dif])
x = -1
ans = []
for i in range(1, n + 1):
if i in gaps:
if x == -1:
x = gaps[i]
elif ans[-1] > gaps[i]:
x = gaps[i]
ans.append(x)
print(*ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
for testcase in range(int(input())):
n = int(input())
a = list(map(int, input().split(" ")))
for i in range(len(a)):
a[i] -= 1
last = [-1] * n
maxdist = [-1] * n
for i in range(len(a)):
maxdist[a[i]] = max(i - last[a[i]] - 1, maxdist[a[i]])
last[a[i]] = i
for i in range(len(maxdist)):
maxdist[i] = max(n - last[i] - 1, maxdist[i])
x = n + 1
y = 0
for i in range(len(maxdist)):
if x > maxdist[i]:
x = maxdist[i]
y = i
ans = [n] * n
for i in range(len(maxdist)):
if maxdist[i] != n:
ans[maxdist[i]] = min(ans[maxdist[i]], i + 1)
minans = n + 1
for i in range(len(ans)):
minans = min(minans, ans[i])
ans[i] = minans
for i in range(len(ans)):
if ans[i] == n and not (y == n - 1 and i >= maxdist[-1]):
ans[i] = -1
print(" ".join(list(map(str, ans))))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
ind = [[] for i in range(n)]
for i in range(n):
ind[a[i] - 1].append(i)
freq = [int(100000000.0)] * n
for i in range(n):
if ind[i] == []:
continue
mx = 0
start = -1
for j in range(len(ind[i])):
mx = max(mx, ind[i][j] - start)
start = ind[i][j]
mx = max(mx, n - start)
freq[mx - 1] = min(freq[mx - 1], i + 1)
for i in range(n):
if freq[i] < int(100000000.0):
start = i
break
freq[i] = -1
m = 100000000.0
for i in range(start, n):
m = min(m, freq[i])
freq[i] = m
print(*freq)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
n = int(input())
a = [int(x) for x in input().split()]
numberLocations = [[-1] for __ in range(n + 1)]
ans = [(-1) for __ in range(n + 1)]
for i in range(n):
numberLocations[a[i]].append(i)
for i in range(n + 1):
numberLocations[i].append(n)
for no in range(n, 0, -1):
maxGap = -float("inf")
temp = numberLocations[no]
for j in range(1, len(temp)):
maxGap = max(maxGap, temp[j] - temp[j - 1])
if maxGap < n + 1:
ans[maxGap] = no
minSoFar = n + 1
for i in range(n + 1):
if ans[i] != -1:
minSoFar = min(minSoFar, ans[i])
ans[i] = min(ans[i], minSoFar)
elif minSoFar != n + 1:
ans[i] = minSoFar
print(" ".join([str(x) for x in ans[1:]]))
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
import sys
r = sys.stdin.readline
for _ in range(int(r())):
n = int(r())
a = [*map(int, r().split())]
dis = [0] * n
loc = [-1] * n
for i in range(n):
t = a[i] - 1
dis[t] = max(dis[t], i - loc[t])
loc[t] = i
dis = [max(dis[i], n - loc[i]) for i in range(n)]
graph = sorted(zip(dis, range(n)))
ans = []
p = 0
m = -2
for i in range(1, n + 1):
while i > graph[p][0]:
p += 1
if i == graph[p][0] and (m < 0 or graph[p][1] < m):
m = graph[p][1]
ans.append(m + 1)
print(*ans)
|
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
for _ in range(int(input())):
n = int(input())
A = list(map(int, input().split()))
f, last, ans = [0] * (n + 1), [-1] * (n + 1), [-1] * (n + 1)
for i, a in enumerate(A):
f[a] = max(f[a], i - last[a])
last[a] = i
for a in range(1, n + 1):
f[a] = max(f[a], n - last[a])
for a in range(1, n + 1):
i = f[a]
while i <= n and ans[i] == -1:
ans[i] = a
i += 1
ans = ans[1:]
print(*ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
T = int(input())
while T > 0:
n = int(input())
arr = list(map(int, input().split()))
dis = [0] * n
dic = {}
res = [-1] * n
for i in range(n):
tmp = arr[i] - 1
if tmp not in dic.keys():
dis[tmp] = max(dis[tmp], i + 1)
else:
dis[tmp] = max(dis[tmp], i - dic[tmp])
dic[tmp] = i
for key in dic.keys():
dis[key] = max(dis[key], n - dic[key])
prev = n
for i in range(n):
if dis[i] == 0:
continue
else:
start = dis[i] - 1
temp = start
while start < prev:
res[start] = i + 1
start += 1
prev = min(prev, temp)
print(*res)
T -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
t = int(input())
for _ in range(t):
n = int(input())
a = [int(x) for x in input().split()]
index = [[0] for _ in range(n + 1)]
ans = [float("inf")] * (n + 1)
for i in range(n):
index[a[i]].append(i + 1)
for j in range(1, n + 1):
if len(index[j]) == 1:
continue
min_idx = -1
for k in range(len(index[j]) - 1):
min_idx = max(index[j][k + 1] - index[j][k], min_idx)
min_idx = max(min_idx, index[j][1], n - index[j][-1] + 1)
ans[min_idx] = min(j, ans[min_idx])
ans2 = [float("inf")]
for k in range(1, n + 1):
ans2.append(min(ans2[k - 1], ans[k]))
for k in range(1, n + 1):
if ans2[k] == float("inf"):
ans2[k] = -1
print(*ans2[1:])
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
from sys import stdin, stdout
outputs = []
t = int(stdin.readline().strip())
for __ in range(t):
n = int(stdin.readline().strip())
res = [n + 2] * n
arr = [int(num) for num in stdin.readline().strip().split()]
req = [[-1, -1, -1] for i in range(n + 1)]
for i in range(n):
if req[arr[i]][0] == -1:
req[arr[i]][0] = i
req[arr[i]][1] = max(i + 1, n - i)
req[arr[i]][2] = 1
elif req[arr[i]][2] == 1:
req[arr[i]][2] += 1
req[arr[i]][1] = max(req[arr[i]][0] + 1, i - req[arr[i]][0])
req[arr[i]][0] = i
else:
req[arr[i]][2] += 1
req[arr[i]][1] = max(req[arr[i]][1], i - req[arr[i]][0])
req[arr[i]][0] = i
for i in range(n):
if req[arr[i]][2] > 1:
req[arr[i]][1] = max(req[arr[i]][1], n - req[arr[i]][0])
for i in range(n):
res[req[arr[i]][1] - 1] = min(arr[i], res[req[arr[i]][1] - 1])
i = 0
while i < n and res[i] == n + 2:
res[i] = "-1"
i += 1
cur_minm = -1 if i > n else res[i]
while i < n:
cur_minm = min(cur_minm, res[i])
res[i] = f"{cur_minm}"
i += 1
outputs.append(" ".join(res))
for output in outputs:
stdout.write(output + "\n")
|
ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER NUMBER BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR STRING
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
g = [[] for i in range(n)]
a = list(map(int, input().split()))
ans = [n + 1] * (n + 2)
for i in range(n):
a[i] -= 1
g[a[i]].append(i)
for x in range(n):
g[x].append(n)
lst = -1
len = 1
for y in g[x]:
len = max(len, y - lst)
lst = y
if ans[len] > x + 1:
ans[len] = x + 1
res = []
cur = n + 1
for i in range(1, n + 1):
cur = min(cur, ans[i])
ans[i] = cur
if ans[i] > n:
ans[i] = -1
res.append(ans[i])
print(*res)
|
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
d = {}
e = [(-1) for i in range(n)]
for i in range(n):
if a[i] in d:
d[a[i]].append(i)
else:
d[a[i]] = [-1, i]
for i in sorted(d):
d[i].append(n)
mx = 0
for j in range(len(d[i]) - 1):
mx = max(d[i][j + 1] - d[i][j] - 1, mx)
for k in range(mx, n):
if e[k] != -1:
break
e[k] = i
print(*e)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
maxn = 300000.0 + 5
def solve(arr, n):
f = [0] * (n + 1)
last = [0] * (n + 1)
ans = [-1] * (n + 1)
for i in range(1, n + 1):
x = arr[i]
f[x] = max(f[x], i - last[x])
last[x] = i
for x in range(1, n + 1):
f[x] = max(f[x], n - last[x] + 1)
i = f[x]
while i <= n and ans[i] == -1:
ans[i] = x
i += 1
print(*ans[1:])
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
arr = [0] + arr
solve(arr, n)
num_inp = lambda: int(input())
arr_inp = lambda: list(map(int, input().split()))
sp_inp = lambda: map(int, input().split())
str_inp = lambda: input()
|
ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
input = __import__("sys").stdin.readline
for _ in range(int(input())):
n = int(input())
s = list(map(int, input().split()))
g = [[-1] for _ in range(n + 1)]
for i in range(n):
g[s[i]].append(i)
inf = 10**10
ans = [-1] * n
lstunused = n
for i in range(1, n + 1):
g[i].append(n)
mx = 0
for j in range(1, len(g[i])):
mx = max(mx, g[i][j] - g[i][j - 1] - 1)
for j in range(mx, lstunused):
ans[j] = i
lstunused = min(lstunused, mx)
print(*ans)
|
ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
t = int(input())
ns = []
for i in range(t):
n = int(input())
arr = list(map(int, input().split()))
nums = set(arr)
dct1 = {}
dct2 = {num: (0) for num in nums}
for idx, el in enumerate(arr):
if el in dct1:
dct2[el] = max(dct2[el], idx - dct1[el])
else:
dct2[el] = idx + 1
dct1[el] = idx
for el in dct2:
dct2[el] = max(dct2[el], n - dct1[el])
ans = []
temp = sorted(nums, key=lambda x: dct2[x])
index = 0
mini = 10**20
for k in range(1, n + 1):
while index < len(temp) and dct2[temp[index]] == k:
mini = min(mini, temp[index])
index += 1
if mini == 10**20:
ans.append(-1)
else:
ans.append(mini)
ns.append(ans)
for el in ns:
print(" ".join(list(map(str, el))))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
for qq in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
last = [-1] * (n + 1)
dura = [-1] * (n + 1)
for i in range(n):
dura[a[i]] = max(dura[a[i]], i - last[a[i]] - 1)
last[a[i]] = i
for i in range(n + 1):
dura[i] = max(dura[i], n - last[i] - 1)
ans = [n + 1] * n
for i in range(n + 1):
if dura[i] == n:
continue
ans[dura[i]] = min(ans[dura[i]], i)
for i in range(n - 1):
ans[i + 1] = min(ans[i + 1], ans[i])
for i in range(n):
if ans[i] == n + 1:
ans[i] = -1
print(*ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
l = [-1] * n
l2 = [-1] * n
for i in range(n):
if l[a[i] - 1] == -1:
l[a[i] - 1] = i
else:
l2[a[i] - 1] = max(l2[a[i] - 1], i - l[a[i] - 1] - 1)
l[a[i] - 1] = i
for i in range(n):
if l2[a[i] - 1] == -1:
l2[a[i] - 1] = max(i, n - i - 1)
l3 = [-1] * n
for i in range(n):
if l3[a[i] - 1] == -1:
l3[a[i] - 1] = i
for i in range(n):
if not l[i] == -1:
l2[i] = max(l2[i], n - l[i] - 1)
if not l3[i] == -1:
l2[i] = max(l2[i], l3[i])
ans = [float("inf")] * n
for i in range(n):
ans[l2[i]] = min(ans[l2[i]], i + 1) if l2[i] != -1 else ans[l2[i]]
for i in range(1, n):
ans[i] = min(ans[i], ans[i - 1])
for i in range(n):
if ans[i] == float("inf"):
ans[i] = -1
print(*ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
def func(n, a):
c = [-1] * (n + 1)
f = [0] * (n + 1)
indices = [[] for _ in range(n + 1)]
for i in range(n):
indices[a[i]].append(i + 1)
for i in range(1, n + 1):
lis = indices[i]
if lis != []:
m = max(lis[0], n - lis[-1] + 1)
for j in range(1, len(lis)):
m = max(m, lis[j] - lis[j - 1])
f[i] = m
for i in range(1, n + 1):
m = f[i]
if m != 0:
while m < n + 1 and c[m] == -1:
c[m] = i
m += 1
return c[1:]
t = int(input())
for i in range(t):
n = int(input())
arr = list(map(int, input().split()))
brr = func(n, arr)
print(" ".join(list(map(str, brr))))
|
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR LIST ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
s = int(input())
for _ in range(s):
n = int(input())
a = [(int(i) - 1) for i in input().split(" ")]
b = a[::-1]
diff = [0] * n
cur = [-1] * n
for i in range(n):
diff[a[i]] = max(diff[a[i]], i - cur[a[i]])
cur[a[i]] = i
cur = [-1] * n
for i in range(n):
diff[b[i]] = max(diff[b[i]], i - cur[b[i]])
cur[b[i]] = i
for i in range(n):
if diff[i] == 0:
diff[i] = 10**6
diff2 = [(diff[i] - 1, i + 1) for i in range(n)] + [(999999, 999999)]
diff2.sort()
ans = [-1] * n
loc = 0
now = diff2[0][1]
for i in range(diff2[0][0], n):
while loc < n - 1 and diff2[loc + 1][0] <= i:
loc += 1
now = min(now, diff2[loc][1])
ans[i] = now
print(" ".join(str(i) for i in ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
for t in range(int(input())):
n = int(input())
a = list(map(int, input().split(" ")))
mp = {}
for i in range(n):
mp[a[i]] = [-1, 0]
for i in range(n):
mp[a[i]][1] = max(i - mp[a[i]][0], mp[a[i]][1])
mp[a[i]][0] = i
for i in range(n):
mp[a[i]][1] = max(n - mp[a[i]][0], mp[a[i]][1])
ans = [(-1) for x in range(n + 1)]
for key, value in mp.items():
for i in range(value[1], n + 1):
if ans[i] <= key and ans[i] != -1:
break
if ans[i] == -1:
ans[i] = key
else:
ans[i] = min(ans[i], key)
for i in range(1, n + 1):
print(ans[i], end=" ")
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
t = int(input())
for w in range(t):
n = int(input())
a = tuple(map(int, input().split()))
d = {}
for i, x in enumerate(a):
if x not in d:
d[x] = [i + 1, i + 1]
else:
d[x] = [i + 1, max(d[x][1], i + 1 - d[x][0])]
l = len(a) + 1
for i in d:
d[i] = max(d[i][1], l - d[i][0])
z = {}
for i, x in d.items():
if x in z:
if z[x] > i:
z[x] = i
else:
z[x] = i
q = [(-1) for x in range(n)]
for i, x in z.items():
q[i - 1] = x
q1 = []
m = -1
for x in q:
if x == -1:
q1.append(m)
else:
if m != -1:
m = min(m, x)
else:
m = x
q1.append(m)
print(" ".join(str(x) for x in q1))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR LIST BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR IF VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
rn = lambda: int(input())
rl = lambda: list(map(int, input().split()))
rns = lambda: map(int, input().split())
rs = lambda: input()
yn = lambda x: print("Yes") if x else print("No")
for _ in range(rn()):
n = rn()
l = rl()
ans = n * [-1]
a = max(l) * [-1]
d = max(l) * [0]
for i in range(n):
d[l[i] - 1] = max(d[l[i] - 1], i - a[l[i] - 1])
a[l[i] - 1] = i
for i in range(max(l)):
d[i] = max(d[i], n - a[i])
for i in set(sorted(l)):
if ans[d[i - 1] - 1] == -1:
ans[d[i - 1] - 1] = i
else:
ans[d[i - 1] - 1] = min(i, ans[d[i - 1] - 1])
m = float("inf")
i = 0
while i < n and ans[i] == -1:
i += 1
m = ans[i]
for j in range(i, n):
if ans[j] == -1:
ans[j] = m
else:
ans[j] = min(ans[j], m)
m = min(m, ans[j])
print(" ".join(list(map(str, ans))))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR LIST NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR LIST NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
import sys
inp = sys.stdin.buffer.readline
inar = lambda: list(map(int, inp().split()))
inin = lambda: int(inp())
inst = lambda: inp().decode().strip()
pr = print
inf = float("inf")
_T_ = inin()
for _t_ in range(_T_):
n = inin()
a = inar()
last = [(-1) for i in range(n + 1)]
gap = [(-1) for i in range(n + 1)]
for inde, i in enumerate(a):
gap[i] = max(gap[i], inde - last[i])
last[i] = inde
for i in a:
gap[i] = max(gap[i], n - last[i])
gapmin = [inf for i in range(n + 1)]
for i in range(1, n + 1):
if gap[i] == -1:
continue
gapmin[gap[i]] = min(gapmin[gap[i]], i)
ans = [inf for i in range(n + 1)]
for i in range(1, n + 1):
ans[i] = min(ans[i - 1], gapmin[i])
for i in range(n + 1):
if ans[i] == inf:
ans[i] = -1
pr(*ans[1:])
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
from sys import stdin, stdout
input = stdin.buffer.readline
for _ in range(int(input())):
n = int(input())
(*a,) = map(int, input().split())
idx = [[-1] for i in range(n + 1)]
for i in range(n):
idx[a[i]].append(i)
for i in range(1, n + 1):
idx[i].append(n)
mn = [[0, i + 1] for i in range(n)]
for i in range(1, n + 1):
for j in range(1, len(idx[i])):
mn[i - 1][0] = max(mn[i - 1][0], idx[i][j] - idx[i][j - 1])
mn.sort()
p = 0
cur = 10000000
for k in range(1, n + 1):
while p < n:
if mn[p][0] > k:
break
cur = min(cur, mn[p][1])
p += 1
if cur == 10000000:
print(-1, end=" ")
else:
print(cur, end=" ")
print()
|
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
import sys
from sys import stdin, stdout
ipi = lambda: int(stdin.readline())
ipil = lambda: map(int, stdin.readline().split())
ipf = lambda: float(stdin.readline())
ipfl = lambda: map(float, stdin.readline().split())
ips = lambda: stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + "\n")
outl = lambda x: print(*x)
T = ipi()
for _ in range(T):
n = ipi()
a = list(ipil())
last_occur = dict()
dis = dict()
for i in range(n):
tmp = a[i]
lst_pos = last_occur.get(tmp)
if lst_pos is None:
last_occur[tmp] = i
dis[tmp] = i + 1
else:
last_occur[tmp] = i
dis[tmp] = max(dis[tmp], i - lst_pos)
for k, v in last_occur.items():
dis[k] = max(dis[k], n - v)
ans = [-1] * n
for k, v in dis.items():
if ans[v - 1] == -1:
ans[v - 1] = k
else:
ans[v - 1] = min(ans[v - 1], k)
flag = -1
for i in range(n):
if ans[i] != -1:
if flag != -1:
ans[i] = min(flag, ans[i])
flag = ans[i]
else:
ans[i] = flag
outl(ans)
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR FOR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
d = dict()
v = dict()
for i in range(n):
d[a[i]] = -1, 0
v[i + 1] = n + 1
for i in range(n):
last, p = d[a[i]]
p_new = i - last
p = max(p_new, p)
d[a[i]] = i, p
ans = n + 1
for k in d.keys():
last, p = d[k]
p_new = n - last
p = max(p_new, p)
v[p] = min(v[p], k)
if p <= ans:
ans = p
v[p] = min(k, v[p])
last = n + 1
for k in range(1, n + 1):
if k < ans:
print(-1, end=" ")
else:
last = min(v[k], last)
print(last, end=" ")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
def ind(lst, m):
result = []
for ab in range(m):
result.append([-1])
for z in range(m):
result[lst[z] - 1].append(z)
for ab in range(m):
result[ab].append(m)
return result
t = int(input())
for i in range(t):
n = int(input())
ans = [-1] * n
a = [int(x) for x in input().split()]
s = set(a)
te = ind(a, n)
for j in s:
maxx = -1
for k in range(len(te[j - 1]) - 1):
maxx = max(maxx, te[j - 1][k + 1] - te[j - 1][k])
for k in range(maxx - 1, n):
if ans[k] != -1:
if ans[k] > j:
ans[k] = j
else:
break
else:
ans[k] = j
print(*ans)
|
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
for _ in range(int(input())):
n = int(input())
a = [int(i) for i in input().split()]
distances = {}
for ind, a_i in enumerate(a):
if a_i not in distances:
distances[a_i] = [ind, ind]
else:
distances[a_i] = [ind, max(ind - distances[a_i][0] - 1, distances[a_i][1])]
for a_i in distances:
distances[a_i][1] = max(len(a) - 1 - distances[a_i][0], distances[a_i][1])
accepted_values = sorted(distances, key=lambda x: (distances[x][1], x))
found_distances = {}
for value in accepted_values:
if distances[value][1] not in found_distances:
found_distances[distances[value][1]] = value
minimum = float("inf")
start = -1
ans = []
for ind in range(n):
if start == -1 and ind in found_distances:
minimum = min(minimum, found_distances[ind])
ans.append(minimum)
start = ind
elif start == -1 and ind not in found_distances:
ans.append(-1)
elif start >= 0 and ind in found_distances:
minimum = min(minimum, found_distances[ind])
ans.append(minimum)
start = ind
elif start >= 0 and ind not in found_distances:
minimum = min(minimum, found_distances[start])
ans.append(minimum)
print(*ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR LIST VAR VAR ASSIGN VAR VAR LIST VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
from sys import stdin, stdout
t = int(input())
for _ in range(t):
n = int(input())
arr = list(map(int, stdin.readline().split()))
s = []
for i in range(n):
s.append([-1, -1])
for i in range(n):
s[arr[i] - 1][0] = max(s[arr[i] - 1][0], i - s[arr[i] - 1][1] - 1)
s[arr[i] - 1][1] = i
for i in range(n):
s[i][0] = max(s[i][0], n - s[i][1] - 1)
ans = [-1] * n
for i in range(n):
for j in range(s[i][0], n):
if ans[j] != -1:
break
else:
ans[j] = i + 1
for i in ans:
stdout.write(str(i) + " ")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
from sys import stdin
T = int(stdin.readline())
for _ in range(T):
n = int(stdin.readline().strip())
a = list(map(int, stdin.readline().strip().split()))
f = [0] * (n + 1)
last = [-1] * (n + 1)
ans = [-1] * (n + 1)
for i in range(0, n):
x = a[i]
f[x] = max(f[x], i - last[x])
last[a[i]] = i
for x in range(1, n + 1):
f[x] = max(f[x], n - last[x])
for j in range(f[x], n + 1):
if ans[j] != -1:
break
ans[j] = x
print(" ".join(map(str, ans[1 : n + 1])))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
def sol(a, n):
pos = [-1] * n
dist = [-1] * n
for i in range(len(a)):
c = a[i] - 1
dist[c] = max(dist[c], i - pos[c] - 1)
pos[c] = i
for i in range(n):
if dist[i] != -1:
dist[i] = max(dist[i], n - pos[i] - 1)
re = [-1] * n
for i in range(n):
if dist[i] != -1:
begin = dist[i]
while begin < n and re[begin] == -1:
re[begin] = i + 1
begin += 1
return re
tc = int(input())
for _ in range(tc):
n = int(input())
a = list(map(lambda x: int(x), input().split(" ")))
re = sol(a, n)
print(*re, sep=" ")
|
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
class PosIndexer:
def __init__(self, nums):
self.build(nums)
def build(self, nums):
self.pos_of_nums = [[] for i in range(len(nums) + 1)]
for num in range(1, len(nums) + 1):
self.pos_of_nums[num].append(0)
for index, num in enumerate(nums):
self.pos_of_nums[num].append(index + 1)
for num in range(1, len(nums) + 1):
self.pos_of_nums[num].append(len(nums) + 1)
def find_max_range_for_num(self, num):
return max(
[
(
self.pos_of_nums[num][pos_index]
- self.pos_of_nums[num][pos_index - 1]
)
for pos_index in range(1, len(self.pos_of_nums[num]))
]
)
def solve(nums):
results = [(-1) for i in range(len(nums) + 1)]
pos_indexer = PosIndexer(nums)
for num in range(1, len(nums) + 1):
max_range_for_num = pos_indexer.find_max_range_for_num(num)
if max_range_for_num <= len(nums) and results[max_range_for_num] == -1:
results[max_range_for_num] = num
for num in range(1, len(nums) + 1):
if results[num - 1] != -1:
if results[num] == -1:
results[num] = results[num - 1]
else:
results[num] = min(results[num], results[num - 1])
return results[1:]
for _ in range(int(input())):
_ = int(input())
nums = [int(token) for token in input().split()]
result = solve(nums)
print(*result)
|
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
import sys
def input():
return sys.stdin.readline()
for _ in range(int(input())):
n = int(input())
A = list(map(int, input().split()))
X = [0] * n
Y = [-1] * n
for i in range(n):
a = A[i]
Y[a - 1] = max(Y[a - 1], i - X[a - 1])
X[a - 1] = i + 1
ans = [-1] * n
for i in range(n):
if X[i]:
Y[i] = max(Y[i], n - X[i])
if ans[Y[i]] == -1:
ans[Y[i]] = i + 1
for i in range(1, n):
if ans[i - 1] != -1:
if ans[i] == -1:
ans[i] = ans[i - 1]
else:
ans[i] = min(ans[i], ans[i - 1])
print(*ans)
|
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$.
Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ elements). If there is no integer occuring in all subsegments of length $k$ for some value of $k$, then the $k$-amazing number is $-1$.
For each $k$ from $1$ to $n$ calculate the $k$-amazing number of the array $a$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the number of elements in the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) β the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print $n$ integers, where the $i$-th integer is equal to the $i$-amazing number of the array.
-----Examples-----
Input
3
5
1 2 3 4 5
5
4 4 4 4 2
6
1 3 1 5 3 1
Output
-1 -1 3 2 1
-1 4 4 4 2
-1 -1 1 1 1 1
-----Note-----
None
|
t = int(input())
for _ in range(t):
n = int(input())
arr = list(map(int, input().split()))
last_same = {}
for a in arr:
last_same[a] = -1, 1
for i, a in enumerate(arr):
last_same[a] = i, max(last_same[a][1], i - last_same[a][0])
for a in last_same.keys():
last_same[a] = last_same[a][0], max(last_same[a][1], len(arr) - last_same[a][0])
ans = [-1] * len(arr)
for a in sorted(list(last_same.keys())):
pos = last_same[a][1] - 1
while pos < len(ans) and ans[pos] == -1:
ans[pos] = a
pos += 1
print(" ".join(map(str, ans)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.