description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
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, ls = int(input()), list(map(int, input().split())) last, dis = [0] * (n + 1), [0] * (n + 1) for i, u in enumerate(ls): i += 1 dis[u] = max(dis[u], i - last[u]) last[u] = i for u in range(n + 1): dis[u] = max(dis[u], n + 1 - last[u]) mnk = [n + 1] * (n + 2) for i, u in enumerate(dis): mnk[u] = min(mnk[u], i) res, pr = [], n + 1 for i in range(1, n + 1): pr = min(pr, mnk[i]) res.append(-1 if pr == n + 1 else pr) print(*res)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER 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 BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR LIST BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER 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()) l = list(map(int, input().split())) l1 = [0] * (n + 1) dis = [-1] + [-1] * n ans = [-1] * (n + 1) count = 0 tt = 0 for i in range(n): if l[i] != l[0] and l1[l[i]] == 0: dis[l[i]] = max(dis[l[i]], i - l1[l[i]] + 1) l1[l[i]] = i else: dis[l[i]] = max(dis[l[i]], i - l1[l[i]]) l1[l[i]] = i for i in range(1, n + 1): if l[-1] != i and dis[i] != -1: dis[i] = max(dis[i], n - l1[i]) d = min(dis) c = dis.index(min(dis)) for i in range(1, n + 1): if dis[i] != -1: if ans[dis[i]] == -1: ans[dis[i]] = i else: ans[dis[i]] = min(ans[dis[i]], i) c = -1 for i in range(1, n + 1): if ans[i] != -1: if c != -1: if c > ans[i]: c = ans[i] else: c = ans[i] print(c, 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR 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 NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN 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
import sys input = sys.stdin.readline def solve_slow(A, n): ans = [(-1) for _ in range(n)] for k in range(n): common = set(A[: k + 1]) for i in range(n - k): common &= set(A[i : i + k + 1]) if common: ans = [(-1) for _ in range(n)] for k in range(n): common = set(A[: k + 1]) for i in range(n - k): common &= set(A[i : i + k + 1]) if common: ans[k] = min(common) return ans def solve_fast(A, n): ans = [(-1) for _ in range(n)] counter = {} for index, a in enumerate(A): if a not in counter: counter[a] = [index] else: counter[a].append(index) for i in range(1, n + 1): if i not in counter: continue indices = counter[i] indices.sort() segment_size = max(indices[0] + 1, n - indices[-1]) for j in range(len(indices) - 1): diff = indices[j + 1] - indices[j] segment_size = max(segment_size, diff) if ans[segment_size - 1] == -1: ans[segment_size - 1] = i for i in range(1, n): if ans[i - 1] == -1: continue if ans[i] == -1 or ans[i - 1] < ans[i]: ans[i] = ans[i - 1] return ans t = int(input()) for x in range(t): n = int(input()) A = list(map(int, input().split(" "))) ans = solve_fast(A, n) print(" ".join(map(str, ans)))
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR ASSIGN VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP 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 VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) d = {} for i in range(n): x = a[i] if not x in d: d[x] = i, i + 1 else: j, r = d[x] d[x] = i, max(i - j, r) nl = [] for x in d.keys(): i, r = d[x] nl.append((max(r, n - i), x)) nl.sort() nl += [(float("inf"), float("inf"))] h = {} r = nl[0][0] i = 0 kmin = nl[0][1] for v in range(r, n + 1): while nl[i][0] <= v: kmin = min(kmin, nl[i][1]) i += 1 h[v] = kmin for i in range(1, nl[0][0]): print(-1, end=" ") for i in h.keys(): print(h[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 DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF 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 ASSIGN VAR LIST FOR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR LIST FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR 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
import sys input = sys.stdin.readline def main(): n = int(input()) alst = list(map(int, input().split())) bef = [(-1) for _ in range(n)] max_d = [(-1) for _ in range(n)] for i, a in enumerate(alst): max_d[a - 1] = max(max_d[a - 1], i - bef[a - 1]) bef[a - 1] = i for i in range(n): max_d[i] = max(max_d[i], n - bef[i]) ans = [(-1) for _ in range(n)] for i, num in enumerate(max_d): for j in range(num - 1, n): if ans[j] != -1: break ans[j] = i + 1 print(*ans) for _ in range(int(input())): main()
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 NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline for _ in range(int(input())): N = int(input()) A = list(map(int, input().split())) idx = [[-1] for _ in range(N + 1)] for i, a in enumerate(A): idx[a].append(i) for i in range(N + 1): idx[i].append(N) ans = [N + 1] * (N + 1) for i in range(1, N + 1): d = 0 for j in range(len(idx[i]) - 1): d = max(d, idx[i][j + 1] - idx[i][j]) if d != N + 1: ans[d] = min(ans[d], i) mi = N + 1 for i in range(1, N + 1): if mi < ans[i]: ans[i] = mi mi = min(mi, ans[i]) if ans[i] == N + 1: ans[i] = -1 print(*ans[1:]) main()
IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF 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 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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER 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 BIN_OP VAR NUMBER 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 VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER 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
def calc(lst, n): if not lst: return n + 1 else: k = 0 prev = -1 for ele in lst: k = max(k, ele - prev) prev = ele k = max(k, n - prev) return k t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) indices = [[] for i in range(n + 1)] i = 0 for ele in a: indices[ele].append(i) i += 1 prev = n ans = [(-1) for i in range(n)] for x in range(1, n + 1): cur = calc(indices[x], n) - 1 for i in range(cur, prev): ans[i] = x prev = min(cur, prev) print(" ".join([str(x) for x in ans]))
FUNC_DEF IF VAR RETURN BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR 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 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL 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 _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) ls = [[] for i in range(n + 5)] for i in range(n): ls[a[i]].append(i) ans = [-1] * n mx = n for i in range(1, n + 1): n1 = len(ls[i]) if n1 > 0: cnt = ls[i][0] for j in range(1, n1): cnt = max(cnt, ls[i][j] - 1 - ls[i][j - 1]) cnt = max(cnt, n - ls[i][-1] - 1) for j in range(cnt, mx): ans[j] = i mx = min(mx, cnt) for i in ans: print(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 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 VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL 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
def amazing_numbers(n, arr): occur_lis = [[] for i in range(n + 1)] for index in range(n): a = arr[index] occur_lis[a].append(index + 1) f = [(0) for i in range(n + 1)] for i in range(1, n + 1): lis = occur_lis[i] if lis != []: m = max(lis[0], n - lis[-1] + 1) for j in range(len(lis) - 1): m = max(m, lis[j + 1] - lis[j]) f[i] = m ans = [(-1) for i in range(n + 1)] for i in range(1, n + 1): if f[i] != 0: p = f[i] while p < n + 1 and ans[p] == -1: ans[p] = i p += 1 return ans[1:] t = int(input()) for i in range(t): n = int(input()) arr = list(map(int, input().split())) brr = amazing_numbers(n, arr) print(" ".join(list(map(str, brr))))
FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL 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 BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER 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 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
t = int(input()) INF = 10**18 for _ in range(t): n = int(input()) A = list(map(int, input().split())) if n == 1: print(A[0]) continue d = {} max_ = {} f = {} for i, a in enumerate(A): if a in d: max_[a] = max(i - d[a], max_[a]) d[a] = i else: max_[a] = 0 d[a] = i f[a] = i for a in max_: if max_[a] == 0: max_[a] = max(d[a] + 1, n - d[a]) else: max_[a] = max(max_[a], f[a] + 1, n - d[a]) ans = [INF] * n for k, v in max_.items(): ans[v - 1] = min(k, ans[v - 1]) for i in range(1, n): ans[i] = min(ans[i - 1], ans[i]) for i in range(n): if ans[i] == INF: ans[i] = -1 print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER 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 IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR FOR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR 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
def solve(): n = int(input()) arr = [int(v) for v in input().split()] distmp = {} lastidx = {} inf = n * 10 ans = [inf] + [inf] * n for i in range(n): if arr[i] in lastidx: distmp[arr[i]] = max(distmp[arr[i]], i - lastidx[arr[i]]) else: distmp[arr[i]] = i + 1 lastidx[arr[i]] = i for k in lastidx.keys(): distmp[k] = max(distmp[k], n - lastidx[k]) for i in range(1, n + 1): if i in distmp: ans[distmp[i]] = min(i, ans[distmp[i]]) for i in range(1, n + 1): ans[i] = min(ans[i - 1], ans[i]) for i in range(n + 1): if ans[i] == inf: ans[i] = -1 print(*ans[1:]) t = int(input()) for _ in range(t): solve()
FUNC_DEF 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 DICT ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP LIST VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR 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 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
t = int(input()) for p in range(t): n = int(input()) b = list(map(int, input().split())) ind = [] for j in range(n + 1): ind.append([-1]) for j in range(n): ind[b[j]].append(j) ord = [] j = 1 while j <= n: if len(ind[j]) < 2: pass else: m = 0 q = 1 while q < len(ind[j]): m = max(m, ind[j][q] - ind[j][q - 1] - 1) q += 1 m = max(m, n - 1 - ind[j][-1]) ord.append([m, j]) j += 1 ord.sort() if n % 2 != 0: ans = [] j = 1 i = 0 m = float("inf") while j <= n: while i < len(ord): if ord[i][0] < j: m = min(m, ord[i][1]) else: break i += 1 if m == float("inf"): ans.append(-1) else: ans.append(m) j += 1 l = n - (n // 2 + 1) j = n // 2 i = n // 2 m = float("inf") while j < n and i >= 0: m = min(m, b[i], b[j]) if ans[l] == -1: ans[l] = float("inf") ans[l] = min(ans[l], m) i += -1 j += 1 l += 1 else: l = n // 2 ans = [] j = 1 i = 0 m = float("inf") while j <= n: while i < len(ord): if ord[i][0] < j: m = min(m, ord[i][1]) else: break i += 1 if m == float("inf"): ans.append(-1) else: ans.append(m) j += 1 j = n // 2 i = n // 2 - 1 m = float("inf") while j < n and i >= 0: m = min(m, b[i], b[j]) if ans[l] == -1: ans[l] = float("inf") ans[l] = min(ans[l], m) i += -1 j += 1 l += 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 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 ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR 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 VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER 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
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) arr = [0] + arr d = dict() dp = [0] * (n + 1) dp1 = [0] * (n + 1) ans = [-1] * (n + 1) for j in range(1, n + 1): i = arr[j] dp[i] = max(dp[i], j - dp1[i]) dp1[i] = j for x in range(1, n + 1): dp[x] = max(dp[x], n - dp1[x] + 1) i = dp[x] while i <= n and ans[i] == -1: ans[i] = x i += 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 BIN_OP LIST NUMBER VAR ASSIGN VAR 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 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
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 nt in range(int(input())): n = int(input()) a = list(map(int, input().split())) minn = {} maxx = {} prev = {} for i in range(n): prev[a[i]] = 0 maxx[a[i]] = 0 for i in range(1, n + 1): diff = i - prev[a[i - 1]] maxx[a[i - 1]] = max(maxx[a[i - 1]], diff) prev[a[i - 1]] = i for i in set(a): diff = n + 1 - prev[i] maxx[i] = max(maxx[i], diff) f = 10**18 for i in maxx: if maxx[i] in minn: minn[maxx[i]] = min(minn[maxx[i]], i) else: minn[maxx[i]] = i f = min(f, maxx[i]) ans = [-1] * n curr = minn[f] for i in range(f, n + 1): if i not in minn: ans[i - 1] = curr continue curr = min(curr, minn[i]) ans[i - 1] = curr 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER 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())) setA = set(A) if len(setA) == 1: print(*([A[0]] * n)) continue last_pos = [-1] * (n + 1) max_dis = [0] * (n + 1) for i, a in enumerate(A): max_dis[a] = max(max_dis[a], i - last_pos[a]) last_pos[a] = i for a in list(setA): max_dis[a] = max(max_dis[a], n - last_pos[a]) res = [-1] * n for i, dis in enumerate(max_dis): if dis == 0: continue elif res[dis - 1] == -1: res[dis - 1] = i for i in range(n - 1): if res[i] != -1: if res[i + 1] > res[i] or res[i + 1] == -1: res[i + 1] = res[i] print(*res)
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 IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST VAR NUMBER 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 VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER 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())) res = [-1] * (n + 1) b = [[] for i in range(n + 1)] for i in range(n): b[a[i]].append(i + 1) p = n for i in range(1, n + 1): if b[i] == []: continue m = 0 m = b[i][0] for j in range(1, len(b[i])): m = max(b[i][j] - b[i][j - 1], m) m = max(m, n + 1 - b[i][-1]) if m > p: continue for k in range(m, p + 1): res[k] = i p = m - 1 print(*res[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 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 ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR LIST ASSIGN 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 VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP 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
t = int(input()) for z in range(t): n = int(input()) a = list(map(int, input().split())) a.insert(0, -1) rast = dict() last = dict() for i in range(1, n + 1): x = a[i] ll = last.get(x, -1) if ll == -1: last[x] = i rast[x] = i else: r = i - ll if r > rast[x]: rast[x] = r last[x] = i ans = [-1] * (n + 1) for h in rast: lb = n + 1 - last[h] if lb > rast[h]: rast[h] = lb r = rast[h] if ans[r] == -1: ans[r] = h elif ans[r] > h: ans[r] = h for k in range(2, n + 1): if (ans[k] > ans[k - 1] or ans[k] == -1) and ans[k - 1] != -1: ans[k] = ans[k - 1] print(*ans[1:])
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 NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP 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
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) last = [(-1) for i in range(n + 1)] gap = [(0) for i in range(n + 1)] for i in range(n): gap[a[i]] = max(gap[a[i]], i - last[a[i]]) last[a[i]] = i for i in range(1, n + 1): gap[i] = max(gap[i], n - last[i]) candidates = [float("inf") for i in range(n + 2)] for i in range(1, n + 1): candidates[gap[i]] = min(candidates[gap[i]], i) mini = float("inf") for k in range(1, n + 1): mini = min(mini, candidates[k]) if mini == float("inf"): print(-1, end=" ") else: print(mini, 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 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 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 VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR FUNC_CALL VAR STRING 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
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = [10**6] * n mn = dict() for i in range(n): if a[i] in mn: mn[a[i]].append(i) else: mn[a[i]] = [i, -1, n] for i in mn: c = 0 mn[i].sort() for j in range(1, len(mn[i])): c = max(c, mn[i][j] - mn[i][j - 1] - 1) b[c] = min(b[c], i) b[-1] = min(a) for i in range(1, n): b[i] = min(b[i], b[i - 1]) for i in range(n): if b[i] == 10**6: b[i] = -1 print(*b)
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 BIN_OP NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR NUMBER VAR FOR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR 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 ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL 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 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
for x in range(int(input())): n = int(input()) m = list(map(int, input().split())) d = {} ind = {} for i in range(n): if m[i] in d: d[m[i]] = max(d[m[i]], i - ind[m[i]]) ind[m[i]] = i else: ind[m[i]] = i d[m[i]] = i + 1 for i in range(n): if ind[m[i]] == i: d[m[i]] = max(d[m[i]], n - i) a = [float("inf")] * n for i in d: a[d[i] - 1] = min(a[d[i] - 1], i) for i in range(1, n): a[i] = min(a[i], a[i - 1]) for i in range(n): if a[i] == float("inf"): a[i] = -1 print(*a)
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 FOR VAR FUNC_CALL VAR VAR IF VAR 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 VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER 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 solve(n): s = list(map(int, input().split())) ind = [[] for _ in range(n + 1)] for i in range(n): ind[s[i]].append(i) ans = [1000000] * (n + 1) for i in range(1, n + 1): k = 0 length = len(ind[i]) if length == 0: continue for j in range(length - 1): k = max(ind[i][j + 1] - ind[i][j], k) k = max(n - ind[i][-1], ind[i][0] + 1, k) for j in range(k, n + 1): if ans[j] <= 300000: break ans[j] = i for i in range(1, n + 1): if ans[i] > 300000: print(-1, end=" ") else: print(ans[i], end=" ") print() for _ in range(int(input())): n = int(input()) solve(n)
FUNC_DEF 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 NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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 INF = 10**18 t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int, input().split())) tmp = [[-1] for _ in range(n + 1)] for i in range(n): tmp[arr[i]].append(i) mins = [INF] * (n + 1) for i in range(1, n + 1): if tmp[i][-1] == -1: continue cnt = 0 prev = tmp[i][0] for val in tmp[i][1:]: cnt = max(cnt, val - prev) prev = val cnt = max(cnt, n - prev) mins[cnt] = min(mins[cnt], i) tmin = INF for i in range(1, n + 1): tmin = min(tmin, mins[i]) if tmin == INF: mins[i] = -1 else: mins[i] = tmin print(*mins[1:])
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 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 LIST VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR VAR VAR NUMBER 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 VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR 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 def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c for j in range(b)] for i in range(a)] def list3d(a, b, c, d): return [[[d for k in range(c)] for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [ [[[e for l in range(d)] for k in range(c)] for j in range(b)] for i in range(a) ] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") INF = 10**19 MOD = 10**9 + 7 EPS = 10**-10 for _ in range(INT()): N = INT() A = LIST() adjli = [[-1] for i in range(N + 1)] for i, a in enumerate(A): adjli[a].append(i) for i in range(1, N + 1): adjli[i].append(N) ans = [INF] * (N + 1) for i in range(1, N + 1): mx = 0 if len(adjli[i]) >= 3: for j in range(len(adjli[i]) - 1): mx = max(mx, adjli[i][j + 1] - adjli[i][j]) if mx != 0: ans[mx] = min(ans[mx], i) for i in range(1, N + 1): ans[i] = min(ans[i], ans[i - 1]) ans = [(a if a != INF else -1) for a in ans] print(*ans[1:])
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NONE RETURN VAR NONE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER 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 LIST NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST 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 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 NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR 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
for t in range(int(input())): n = int(input()) a = list(map(int, input().split())) x = 300005 f1 = {} f2 = {} ans = [x] * n for i in range(n): f1[a[i]] = -1 f2[a[i]] = 0 for i in range(n): f2[a[i]] = max(f2[a[i]], i - f1[a[i]]) f1[a[i]] = i for i in range(n): f2[a[i]] = max(f2[a[i]], n - f1[a[i]]) for i in range(n): ans[f2[a[i]] - 1] = min(a[i], ans[f2[a[i]] - 1]) ans[-1] = min(a) for i in range(1, n): ans[i] = min(ans[i], ans[i - 1]) for i in range(n): if ans[i] == x: 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 NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER 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 ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL 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 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
gans = [] for _ in range(int(input())): n = int(input()) u = list(map(int, input().split())) d = dict() w = [] v = [] ind = 0 for i in range(n): if u[i] not in d.keys(): d[u[i]] = ind w.append([]) w[ind].append(i) ind += 1 v.append(u[i]) else: w[d[u[i]]].append(i) m = ind vans = [0] * m for i in range(m): mx = max(w[i][0] + 1, n - w[i][-1]) for j in range(1, len(w[i])): mx = max(w[i][j] - w[i][j - 1], mx) vans[i] = mx, -v[i] vans.sort() ans = [0] * n vv = [-1] * n ind = 0 for i in range(n): if vans[ind][0] > i + 1: continue while ind + 1 < len(vans) and vans[ind + 1][0] <= i + 1: ind += 1 vv[i] = -vans[ind][1] if i > 0 and vv[i - 1] != -1: vv[i] = min(vv[i], vv[i - 1]) gans.append(" ".join(map(str, vv))) print("\n".join(gans))
ASSIGN VAR LIST 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 ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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 _ in range(int(input())): n = int(input()) ar = list(map(int, input().split())) dic = {} for i in range(n): if ar[i] in dic: dic[ar[i]].append(i) else: dic[ar[i]] = [-1, i] for i in dic: dic[i].append(n) ans = [-1] * (n + 1) for i in dic: ma = -float("inf") for j in range(1, len(dic[i])): ma = max(ma, dic[i][j] - dic[i][j - 1]) if ans[ma] != -1: ans[ma] = min(ans[ma], i) else: ans[ma] = i pre = -1 for i in range(1, n + 1): if pre == -1: if ans[i] != -1: pre = ans[i] elif ans[i] != -1: ans[i] = min(pre, ans[i]) pre = min(pre, ans[i]) else: ans[i] = pre print(*ans[1:])
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT 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 VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR 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 input = sys.stdin.readline t = int(input()) for case in range(t): n = int(input()) a = [int(x) for x in input().split(" ")] b = sorted(a) dict = {} for i, x in enumerate(a): if x in dict.keys(): dict[x] += [i] else: dict[x] = [i] c = [[k, [-1] + v + [n]] for k, v in dict.items()] c.sort(key=lambda x: x[0]) d = [] for y in c: m = 1 for i in range(1, len(y[1])): m = max(y[1][i] - y[1][i - 1], m) d.append([y[0], m]) ans = [] j = n for item in d: ans.extend([item[0]] * max(0, j - item[1] + 1)) if item[1] <= j: j = item[1] - 1 ans += [-1] * (n - len(ans)) print(*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 STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR LIST VAR ASSIGN VAR VAR LIST VAR ASSIGN VAR LIST VAR BIN_OP BIN_OP LIST NUMBER VAR LIST VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR LIST VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP LIST NUMBER BIN_OP VAR FUNC_CALL 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 input = iter(sys.stdin.read().splitlines()).__next__ t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) occurrences = [[-1] for _ in range(n + 1)] for i, a_i in enumerate(a): occurrences[a_i].append(i) subsegment_lengths = [] for val, occ in enumerate(occurrences): if len(occ) == 1: continue occ.append(n) min_k = max(occ[i + 1] - occ[i] for i in range(len(occ) - 1)) subsegment_lengths.append((val, min_k)) k_amazing = [n + 1] * n for num, k in subsegment_lengths: k_amazing[k - 1] = min(num, k_amazing[k - 1]) for i in range(1, n): k_amazing[i] = min(k_amazing[i], k_amazing[i - 1]) for i, num in enumerate(k_amazing): if num > n: k_amazing[i] = -1 print(*k_amazing)
IMPORT ASSIGN VAR FUNC_CALL VAR 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 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 LIST FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER VAR FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF 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
t = int(input()) ans = [[] for i in range(t)] for i in range(t): n = int(input()) list_a = [*map(int, input().split())] dict_a = {value_a: [] for value_a in set(list_a)} for j in range(n): value = list_a[j] dict_a[value].append(j) ans_dict_a = { value_a: max( [*map(lambda x, y: x - y, dict_a[value_a] + [n], [-1] + dict_a[value_a])] ) for value_a in dict_a.keys() } ans_list = [(-1) for i in range(n)] q = n for value in sorted(dict_a.keys()): p = ans_dict_a[value] - 1 for k in range(p, q): ans_list[k] = value if q > p: q = p ans[i] = ans_list for an in ans: print(" ".join(map(str, an)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR LIST FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR LIST VAR BIN_OP LIST NUMBER VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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
from sys import stdin input = stdin.readline q = int(input()) for _ in range(q): n = int(input()) l = list(map(int, input().split())) for i in range(n): l[i] -= 1 miej = [[-1] for i in range(n)] for i in range(n): miej[l[i]].append(i) for i in range(n): miej[i].append(n) dupa = [0] * n for i in range(n): k = len(miej[i]) for j in range(1, k): dupa[i] = max(dupa[i], miej[i][j] - miej[i][j - 1]) cyk = [[dupa[i], i] for i in range(n)] cyk.append([1, 1000000]) cyk.sort() odp = [0] * n ind = 0 best = cyk[0][1] for k in range(1, n + 1): while ind + 1 < n and cyk[ind + 1][0] <= k: best = min(best, cyk[ind + 1][1]) ind += 1 if best >= 1000000: odp[k - 1] = -1 else: odp[k - 1] = best + 1 print(*odp)
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 FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL 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 NUMBER BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER 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 i in range(t): n = int(input()) a = [int(x) for x in input().split()] dct = {} for i in a: dct[i] = -1, 0 now = 0 for i in a: dct[i] = [now, max(dct[i][1], now - dct[i][0])] now += 1 for i in dct: dct[i] = max(dct[i][1], n - dct[i][0]) a = [(dct[i], i) for i in dct] a.sort() mini = 1000000000000000 now = 0 q = len(a) for i in range(1, n + 1): while now < q and a[now][0] == i: mini = min(mini, a[now][1]) now += 1 if mini == 1000000000000000: print(-1, end=" ") else: print(mini, 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR LIST VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR NUMBER FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR 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
def solve(): n = int(input().strip()) a = list(map(int, input().strip().split())) last_occur = [(-1) for i in range(n + 1)] max_dist = [(0) for i in range(n + 1)] max_dist[0] = n for i in range(n): elem = a[i] dist = i - last_occur[elem] - 1 max_dist[elem] = max(dist, max_dist[elem]) last_occur[elem] = i for i in range(n): elem = i + 1 dist = n - last_occur[elem] - 1 max_dist[elem] = max(dist, max_dist[elem]) max_dist = [(max_dist[i], i) for i in range(1, n + 1)] max_dist.sort() cursor = 0 min_so_far = n + 1 for k in range(1, n + 1): while cursor < n and max_dist[cursor][0] < k: min_so_far = min(max_dist[cursor][1], min_so_far) cursor += 1 if min_so_far == n + 1: print(-1, end=" ") else: print(min_so_far, end=" ") print() t = int(input().strip()) for _ in range(t): solve()
FUNC_DEF 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 NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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
t = int(input()) for case in range(t): n = int(input()) a = [(int(x) - 1) for x in input().split()] last_occ = [(-1) for _ in range(n)] max_dist = [float("-inf") for _ in range(n)] for i, x in enumerate(a): max_dist[x] = max(max_dist[x], i - last_occ[x]) last_occ[x] = i for x in a: max_dist[x] = max(max_dist[x], n - last_occ[x]) inverted = [float("inf") for _ in range(n)] for x in a: inverted[max_dist[x] - 1] = min(inverted[max_dist[x] - 1], x) best = float("inf") for x in inverted: if x != float("inf"): best = min(x, best) if best == float("inf"): print(-1, end=" ") else: print(best + 1, 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 BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR 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 VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR IF VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER 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 tests = int(input()) for case in range(tests): n = int(input()) ans = [1000000001] * n a = list(map(int, input().split())) k = dict() for i in range(n): if a[i] not in k: k[a[i]] = [i] else: k[a[i]].append(i) z = dict() for key in k: d = 0 if k[key][0] != 0: d = max(d, k[key][0] + 1) for i in range(1, len(k[key])): d = max(d, abs(k[key][i] - k[key][i - 1])) if k[key][-1] != n - 1: d = max(d, n - k[key][-1]) if d in z: z[d] = min(z[d], key) else: z[d] = key for i in range(len(ans)): if i > 0: if i + 1 in z: ans[i] = min( z[i + 1], ( ans[i - 1] if ans[i - 1] != -1 and ans[i - 1] != 1000000001 else z[i + 1] ), ) elif ans[i - 1] == -1 or ans[i - 1] == 1000000001: ans[i], ans[i - 1] = -1, -1 else: ans[i] = ans[i - 1] elif i + 1 in z: ans[i] = z[i + 1] else: ans[i] = -1 print(*ans)
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 BIN_OP LIST NUMBER 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 ASSIGN VAR VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR 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 i in range(t): n = int(input()) l = list(map(int, input().split())) d = {} for j in range(n): if l[j] not in d: d[l[j]] = [j] else: d[l[j]].append(j) d1 = {} for j in d: d[j].sort() m = d[j][0] + 1 for k in range(1, len(d[j])): m = max(m, d[j][k] - d[j][k - 1]) m = max(m, n - d[j][len(d[j]) - 1]) if m not in d1: d1[m] = j else: d1[m] = min(d1[m], j) l1 = [-1] * n m = min(list(d1)) l1[m - 1] = d1[m] for j in range(m + 1, n + 1): if j in d1: l1[j - 1] = min(d1[j], l1[j - 2]) else: l1[j - 1] = l1[j - 2] print(*l1)
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 FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER 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
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) d = {} for i in range(len(l)): x = l[i] if x in d: d[x].append(i + 1) else: d[x] = [0] d[x].append(i + 1) ans = [(10**18) for i in range(n + 1)] for x in d: p = d[x] cnt = 0 for i in range(len(p)): if i == len(p) - 1: cnt = max(cnt, n - p[i] + 1) else: cnt = max(cnt, p[i + 1] - p[i]) if cnt < n + 1: ans[cnt] = min(ans[cnt], x) m = 10**18 for i in range(1, len(ans)): m = min(m, ans[i]) ans[i] = m if m == 10**18: ans[i] = -1 print(*ans[1:])
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR LIST NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP NUMBER NUMBER 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
import sys def main(): n = int(sys.stdin.readline().strip()) q = list(map(int, sys.stdin.readline().split())) clovar, p, x = {}, [], 1000000000.0 for i in range(n): if q[i] in clovar: clovar[q[i]].append(i) else: clovar[q[i]] = [i] for o in clovar: t = clovar[o] ma = max(t[0] + 1, n - t[-1]) dlinat = len(t) - 1 for i in range(dlinat): ma = max(t[i + 1] - t[i], ma) p.append([ma, o]) p.sort() ans = [p[0]] dlinap = len(p) for i in range(1, dlinap): if ans[-1][0] != p[i][0]: ans.append(p[i]) ans.append([n + 1, 1000000000.0]) dlina_1 = ans[0][0] - 1 print(*[(-1) for i in range(dlina_1)], end=" ") dlinaans = len(ans) - 1 for i in range(dlinaans): x = min(x, ans[i][1]) dlinax = ans[i + 1][0] - ans[i][0] print(*[x for o in range(dlinax)], end=" ") print() for i in range(int(sys.stdin.readline().strip())): main()
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR DICT LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL 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
t = int(input()) for j in range(t): n = int(input()) l = list(map(int, input().split())) ans = [(-1) for j in range(n + 3)] d = {} la = l[-1] f = l[0] for j in range(n): if l[j] not in d: d[l[j]] = [] if f != l[j]: d[l[j]].append(-1) d[l[j]].append(j) for k in d: m = 0 if k != la: d[k].append(n) for j in range(len(d[k]) - 1): if d[k][j + 1] - d[k][j] > m: m = d[k][j + 1] - d[k][j] if ans[m] == -1: ans[m] = k else: ans[m] = min(ans[m], k) m = n a = False for j in range(1, n + 1): if ans[j] != -1: m = min(m, ans[j]) a = True if a: ans[j] = m print(*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 VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL 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
import sys def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) def solve(): p = dict() b = dict() i = 0 n = mint() for x in mints(): if x in p: b[x] = max(b[x], i - p[x]) else: b[x] = i + 1 p[x] = i i += 1 res = [] for x, y in b.items(): res.append((max(b[x], n - p[x]), x)) res.sort() j = 0 cur = int(1000000000.0) rr = [-1] * n for i in range(1, n + 1): while j < len(res) and res[j][0] <= i: cur = min(cur, res[j][1]) j += 1 if cur <= n: rr[i - 1] = cur print(" ".join(map(str, rr))) for i in range(mint()): solve()
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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 VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL 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
T = int(input()) for _ in range(T): n = int(input()) a = [(int(x) - 1) for x in input().split()] prev = [(-1) for _ in range(n)] val = [(1) for _ in range(n)] for i, x in enumerate(a): delta = i - prev[x] val[x] = max(val[x], delta) prev[x] = i for i in range(n): val[i] = max(val[i], n - prev[i]) ans = [(-1) for _ in range(n + 1)] r = n + 1 for i in range(n): if val[i] < r: for j in range(val[i], r): ans[j] = i + 1 r = val[i] print(" ".join([str(x) for x in ans[1:]]))
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 ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR 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
t = int(input()) for _ in range(t): n = int(input()) a = [0] + list(map(int, input().split())) period = [(0) for i in range(n + 1)] first = [(-1) for i in range(n + 1)] last = [(-1) for i in range(n + 1)] for i in range(1, len(a)): b = a[i] if first[b] == -1: first[b] = i last[b] = i else: period[b] = max(period[b], i - last[b]) last[b] = i for i in range(1, len(period)): period[i] = max(period[i], n - last[i] + 1) period = period[1:] l = sorted( list( e if e[0] > first[e[1]] else (first[e[1]], e[1]) for e in zip(period, range(1, n + 1)) if e[0] > 0 ) ) ans = [] AA = n + 5 ind = 0 for i in range(1, n + 1): if ind < len(l) and l[ind][0] == i: AA = min(AA, l[ind][1]) ans.append(-1 if AA == n + 5 else AA) while ind < len(l) and l[ind][0] == i: ind += 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 BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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 ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR 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 FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER 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())) di = dict() di2 = dict() for i in range(n): if arr[i] not in di: di2[arr[i]] = 0 di[arr[i]] = -1 di2[arr[i]] = max(di2[arr[i]], i - di[arr[i]]) di[arr[i]] = i for i in range(n): di2[arr[i]] = max(di2[arr[i]], n - di[arr[i]]) ans = [(-1) for _ in range(n)] lflt = n + 1 for each in sorted(k for k in di): if di2[each] >= lflt: continue for i in range(di2[each] - 1, lflt - 1): ans[i] = each lflt = di2[each] 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR 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 VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER 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 j in range(int(input())): n = int(input()) a = list(map(int, input().split())) d = [[-1, -1]] * (n + 1) for i in range(n): y = a[i] s = max(d[y][1], i - d[y][0]) d[y] = [i, s] for i in range(n + 1): d[i][1] = max(d[i][1], n - d[i][0]) y = [i for i in range(1, n + 1)] y.sort(key=lambda x: d[x][1]) ans = [0] * n z = 0 p = 10**6 for i in range(1, n + 1): while z < n and i >= d[y[z]][1]: p = min(p, y[z]) z += 1 if p == 10**6: ans[i - 1] = -1 else: ans[i - 1] = p 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 LIST NUMBER NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR LIST VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER 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 def prog(): for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) locs = [[-1] for u in range(n + 1)] for i in range(n): locs[a[i]].append(i) for i in range(1, n + 1): locs[i].append(n) b = [] for i in range(1, n + 1): if len(locs[i]) > 1: gap = 0 for j in range(1, len(locs[i])): gap = max(gap, locs[i][j] - locs[i][j - 1]) b.append([gap, i]) b.sort() idx = 0 mn = 10**9 output = [0] * n for k in range(1, n + 1): while idx < len(b) and k >= b[idx][0]: mn = min(mn, b[idx][1]) idx += 1 if idx == 0: output[k - 1] = -1 else: output[k - 1] = mn print(*output) prog()
IMPORT ASSIGN VAR VAR 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 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 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 NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR 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 readline = sys.stdin.readline T = int(readline()) Ans = [None] * T INF = 10**9 + 7 for qu in range(T): N = int(readline()) A = list(map(int, readline().split())) table = [-1] * (N + 1) pre = [-1] * (N + 1) for i in range(N): a = A[i] table[a] = max(table[a], i - pre[a]) pre[a] = i for a in range(1, N + 1): table[a] = max(table[a], N - pre[a]) leng = [INF] * (N + 1) for a in range(N, 0, -1): if table[a] == N + 1: continue leng[table[a]] = a for i in range(2, N + 1): leng[i] = min(leng[i], leng[i - 1]) for i in range(1, N + 1): if leng[i] == INF: leng[i] = -1 Ans[qu] = " ".join(map(str, leng[1:])) print("\n".join(Ans))
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR 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 VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING 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, a): maxD = [1] * (n + 1) lastP = [-1] * (n + 1) for i in range(n): d = i - lastP[a[i]] maxD[a[i]] = max(maxD[a[i]], d) lastP[a[i]] = i res = [-1] * n k = n for v in range(1, n + 1): if lastP[v] == -1: continue minK = max(maxD[v], n - lastP[v]) while k >= minK: res[k - 1] = v k -= 1 return res tests = int(input()) for test in range(tests): n = int(input()) a = list(map(int, input().split())) print(*solve(n, a))
FUNC_DEF 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 BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR 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 VAR FUNC_CALL FUNC_CALL VAR EXPR 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 input = sys.stdin.readline def inp(): return int(input()) def inlt(): return list(map(int, input().split())) test_cases = inp() max_poss = 3123456 def solve(): n = inp() arr = inlt() max_dist = {} last_ind = {} for ind, num in enumerate(arr): dist = ind - last_ind.get(num, -1) if num not in max_dist: max_dist[num] = dist else: max_dist[num] = max(max_dist[num], dist) last_ind[num] = ind for num, last_index in last_ind.items(): dist = n - last_index max_dist[num] = max(max_dist[num], dist) answers_rev = {} for num, dist in max_dist.items(): if dist not in answers_rev: answers_rev[dist] = num else: answers_rev[dist] = min(answers_rev[dist], num) ans = "" min_number_found = None for i in range(1, n + 1): answer = answers_rev.get(i, max_poss) if answer != max_poss: if min_number_found is None: min_number_found = answer if answer < min_number_found: min_number_found = answer if min_number_found is not None: ans += "{}".format(min_number_found) else: ans += "-1".format(min_number_found) if i < n: ans += " " else: ans += "\n" print(ans) for test in range(test_cases): solve()
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR 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 STRING ASSIGN VAR NONE FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR NONE ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NONE VAR FUNC_CALL STRING VAR VAR FUNC_CALL STRING VAR IF VAR VAR VAR STRING VAR STRING EXPR FUNC_CALL VAR 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
MAXN = 300005 t = int(input()) for _ in range(t): n = int(input()) a = map(int, input().split()) lst = [0] * (n + 5) ai_sep = [-1] * (n + 5) for i, ai in enumerate(a, 1): ai_sep[ai] = ai_sep[ai] if ai_sep[ai] > i - lst[ai] else i - lst[ai] lst[ai] = i sep_ai = [MAXN] * (n + 5) for ai, sep in enumerate(ai_sep): if sep is -1: continue sep = ai_sep[ai] = ( ai_sep[ai] if ai_sep[ai] > n + 1 - lst[ai] else n + 1 - lst[ai] ) sep_ai[sep] = sep_ai[sep] if sep_ai[sep] < ai else ai sep_ai[0] = -1 for sep in range(1, n + 1): if sep_ai[sep] == MAXN: sep_ai[sep] = sep_ai[sep - 1] elif sep_ai[sep - 1] != -1: sep_ai[sep] = ( sep_ai[sep - 1] if sep_ai[sep - 1] < sep_ai[sep] else sep_ai[sep] ) print(*sep_ai[1 : n + 1])
ASSIGN 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 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 NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL 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
t = input() t = int(t) def solve(n, arr): ans = [float("inf") for _ in range(n)] pos = {} dist = {} for i in range(n): pos[arr[i]] = 0 dist[arr[i]] = 0 for i in range(n): dis = i + 1 - pos[arr[i]] dist[arr[i]] = max(dis, dist[arr[i]]) pos[arr[i]] = i + 1 for i in range(n): dis = n + 1 - pos[arr[i]] dist[arr[i]] = max(dis, dist[arr[i]]) for i in range(n): if i + 1 in dist and i + 1 < ans[dist[i + 1] - 1]: ans[dist[i + 1] - 1] = i + 1 seed = ans[0] for i in range(1, n): if ans[i] < seed: seed = ans[i] else: ans[i] = seed for i in range(n): if ans[i] == float("inf"): ans[i] = -1 print(*ans) for i in range(t): n = input() n = int(n) arr = list(map(int, input().split())) solve(n, arr)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) a = list(map(int, input().split(" "))) l = [-1] * n u = [-1] * n k = [-1] * n for x in range(n): i = a[x] - 1 l[i] = max(l[i], x - u[i]) u[i] = x m = n i = [x for x in range(n) if l[x] != -1] for x in i: a = max(l[x], n - u[x]) if l[x] <= m and k[a - 1] == -1: for j in range(a - 1, m): k[j] = x + 1 m = a - 1 print(*k)
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER 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 VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN 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()) a = list(map(int, input().split())) dic = {} for i in range(n): temp = dic.get(a[i], 0) if temp == 0: dic[a[i]] = [i + 1, 0, n - i] else: dic[a[i]] = [temp[0], max(temp[1], temp[2] - (n - i)), n - i] lis = [] ans = [300001] * n for k, v in dic.items(): MAX = max(v) ans[MAX - 1] = min(k, ans[MAX - 1]) if ans[0] == 300001: ans[0] = -1 for i in range(1, n): if ans[i - 1] == -1: if ans[i] == 300001: ans[i] = -1 else: ans[i] = min(ans[i - 1], ans[i]) print(" ".join(str(n) for n 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR LIST BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR ASSIGN VAR VAR VAR LIST VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER 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 anynumber in range(int(input())): n = int(input()) l = list(map(int, input().split())) d = {} for index, i in enumerate(l): if i not in d.keys(): d[i] = [index + 1, index] else: d[i] = [max(index - d[i][1], d[i][0]), index] for i in d.keys(): d[i] = max(d[i][0], n - d[i][1]) ans = [(-1) for i in range(n)] for i in sorted(d.keys(), reverse=True): ans[d[i] - 1] = i for i in range(1, n): if ans[i] == -1: ans[i] = ans[i - 1] elif ans[i - 1] != -1: if ans[i - 1] < ans[i]: ans[i] = ans[i - 1] for i in range(n - 1): print(ans[i], end=" ") print(ans[n - 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 DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR LIST BIN_OP VAR NUMBER VAR ASSIGN VAR VAR LIST FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR 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
for tc in range(int(input())): n = int(input()) s = list(map(int, input().split())) prev = [(-1) for i in range(n + 1)] maxGap = [(-1) for i in range(n + 1)] for i in range(len(s)): if i - prev[s[i]] > maxGap[s[i]]: maxGap[s[i]] = i - prev[s[i]] prev[s[i]] = i for i in range(n): if maxGap[i] != -1 and n - prev[i] > maxGap[i]: maxGap[i] = n - prev[i] k = [(1000000) for i in range(n)] for i in range(1, len(maxGap)): if maxGap[i] != -1: if k[maxGap[i] - 1] > i: k[maxGap[i] - 1] = i best = 2000000 for i in range(len(k)): if k[i] == 1000000 and best == 2000000: k[i] = -1 elif k[i] > best: k[i] = best else: best = k[i] print(" ".join(map(str, k)))
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 BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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 read_line(): return list(map(int, input().split())) def A(d, i, x): if x not in d: d[x] = [-1, i] return d[x][0] = max(i - d[x][1], d[x][0]) d[x][1] = i T = int(input()) for _ in range(T): n = int(input()) l = read_line() d = {} s = {} for x in l: if x in s: continue s[x] = 1 A(d, -1, x) for i, x in enumerate(l): A(d, i, x) s = {} for x in l: if x in s: continue s[x] = 1 A(d, n, x) ans = [None] * (n + 1) for x in sorted(d.keys()): val = x gap = d[x][0] if ans[gap] is None or ans[gap] > val: ans[gap] = val for i in range(2, n + 1): if ans[i - 1] is None: continue if ans[i] is None: ans[i] = ans[i - 1] ans[i] = min(ans[i], ans[i - 1]) print(" ".join(map(lambda x: "-1" if x is None else str(x), ans[1:])))
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR ASSIGN VAR VAR LIST NUMBER VAR RETURN ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER 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 ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR NONE VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NONE IF VAR VAR NONE 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 FUNC_CALL STRING FUNC_CALL VAR VAR NONE 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
t = int(input()) for _ in range(t): n = int(input()) arr = [int(x) for x in input().split()] dict = {} for i in range(n): if arr[i] in dict: dict[arr[i]].append(i) else: dict[arr[i]] = [-1, i] for i in dict: dict[i].append(n) out = [(-1) for x in range(n)] for i in sorted(dict.keys()): m = -1 for j in range(len(dict[i]) - 1): m = max(m, dict[i][j + 1] - dict[i][j] - 1) for j in range(m, n): if out[j] != -1: break out[j] = i print(*out)
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 DICT 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 VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER 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
for _ in range(int(input())): n = int(input()) lis = list(map(int, input().split())) d = {} for i in range(n): if lis[i] not in d: d[lis[i]] = [] d[lis[i]].append(i) else: d[lis[i]].append(i) for i in d: d[i].append(n) ans = [1000000000000] * n for i in d: pre = -1 mx = 0 for j in d[i]: mx = max(mx, j - pre) pre = j if ans[mx - 1] == -1: ans[mx - 1] = i else: ans[mx - 1] = min(ans[mx - 1], i) prev = 1000000000000 for i in range(n): ans[i] = min(ans[i], prev) prev = min(ans[i], prev) for i in range(n): if ans[i] == 1000000000000: 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 DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR 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 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 ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF 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
from sys import stdin t = int(stdin.readline()) for case in range(t): n = int(stdin.readline()) array = list(map(int, stdin.readline().split())) dict1 = {} dict2 = {} ans = [-1] * n for i in range(n): if array[i] not in dict2: dict2[array[i]] = i dict1[array[i]] = i else: dict2[array[i]] = max(dict2[array[i]], i - dict1[array[i]] - 1) dict1[array[i]] = i for i in dict2: dict2[i] = max(dict2[i], n - dict1[i] - 1) sorts = sorted(list(dict2.keys())) for i in sorts: for j in range(dict2[i], n): if ans[j] != -1: break else: ans[j] = i 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR 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 VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR IF 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 _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) ind = [[0] for i in range(n + 1)] maxi = int(100000000.0) ans = [maxi] * (n + 1) for i in range(n): ind[a[i]].append(i + 1) for i in range(n + 1): ind[i].append(n + 1) for i in range(1, n + 1): pre, m = 0, 0 for j in range(1, len(ind[i])): m = max(m, ind[i][j] - pre) pre = ind[i][j] if m < n + 1: ans[m] = min(ans[m], i) val = ans[1] for i in range(1, n + 1): ans[i] = min(val, ans[i]) val = ans[i] if ans[i] == maxi: ans[i] = -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 LIST NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST 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 BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR 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
for _ in range(int(input())): n = int(input()) l = [int(x) for x in input().split()] d = {} for i in range(n): if l[i] not in d: d[l[i]] = [i + 1] else: temp = d[l[i]] temp.append(i + 1) d[l[i]] = temp for i in d: d[i].append(n + 1) for i in d: temp = d[i] arr = [0] * len(temp) arr[0] = temp[0] for j in range(1, len(temp)): arr[j] = temp[j] - temp[j - 1] d[i] = arr newdic = {} for i in d: newdic[i] = max(d[i]) index = {} for i in newdic: if newdic[i] in index: index[newdic[i]].append(i) else: index[newdic[i]] = [i] ans = [0] * (n + 1) for i in range(1, n + 1): if i not in index: if ans[i - 1] == 0: ans[i] = -1 else: ans[i] = ans[i - 1] elif ans[i - 1] > 0: ans[i] = min(min(index[i]), ans[i - 1]) else: ans[i] = min(index[i]) 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 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 BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL 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
def main(): n = int(input()) a = list(map(int, input().split())) p = [(-1) for _ in range(n)] f = [(0) for _ in range(n)] for i in range(n): element = a[i] - 1 f[element] = max(f[element], i - p[element]) p[element] = i ans = [(-1) for _ in range(n + 1)] for x in range(n): f[x] = max(f[x], n - p[x]) i = f[x] while i <= n and ans[i] == -1: ans[i] = x + 1 i += 1 for c in ans[1:]: print(c, end=" ") print("") for _ in range(int(input())): main()
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 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 NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 = lambda: sys.stdin.readline().rstrip() T = int(input()) for _ in range(T): N = int(input()) A = [(int(a) - 1) for a in input().split()] X = [-1] * N Y = [0] * N for i, a in enumerate(A): Y[a] = max(Y[a], i - X[a] - 1) X[a] = i for i in range(N): Y[i] = max(Y[i], N - X[i] - 1) ANS = [N + 1] * (N + 1) for i, a in enumerate(Y): ANS[a] = min(ANS[a], i + 1) for i in range(1, N + 1): ANS[i] = min(ANS[i], ANS[i - 1]) print(*[(a if a <= N else -1) for a in ANS[:-1]])
IMPORT ASSIGN VAR 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 FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR 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 BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR 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 BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER 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 = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) last = [-1] * (n + 1) best = [1] * (n + 1) for i in range(n): v = l[i] diff = i - last[v] best[v] = max(best[v], diff) last[v] = i for v in range(n + 1): diff = n - last[v] best[v] = max(best[v], diff) rev = [n + 1] * (n + 2) for i in range(n, -1, -1): rev[best[i]] = i soFar = n + 1 out = [] for i in range(1, n + 1): soFar = min(soFar, rev[i]) if soFar > n: out.append(-1) else: out.append(soFar) print(" ".join(map(str, out)))
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 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 ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER 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 FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: n = len(ages) if n < 2: return 0 ages.sort() mins = [0] * n pairs = [0] * n mins[0] = ages[0] / 2 + 7 for i in range(1, n): mins[i] = (ages[i] - ages[i - 1]) / 2 + mins[i - 1] if ages[i - 1] <= mins[i]: continue if mins[i] == mins[i - 1]: pairs[i] = pairs[i - 1] + 2 continue j = i - 1 while j >= 0 and ages[j] > mins[i]: pairs[i] += 1 if ages[j] == ages[i]: pairs[i] += 1 j -= 1 return sum(pairs)
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: ageIdx = defaultdict(list) for i, age in enumerate(ages): ageIdx[age].append(i) count = 0 for age in ageIdx: lowerBound = int(1 / 2 * age) + 7 + 1 upperBound = age for A in ageIdx[age]: for candAge in range(lowerBound, upperBound + 1): if candAge in ageIdx: if candAge != age: count += len(ageIdx[candAge]) else: count += len(ageIdx[candAge]) - 1 return count
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: count = Counter(ages) ans = 0 for i in count: for j in count: if not (j <= i * 0.5 + 7 or j > i): ans += count[i] * count[j] if j == i: ans -= count[i] return ans
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: count = 0 counter = [0] * 121 for i in ages: counter[i] += 1 for a in range(1, 121): for b in range(1, 121): if b > a: continue if b <= 0.5 * a + 7: continue if b > 100 and a < 100: continue count += counter[a] * counter[b] if a == b: count -= counter[a] return count
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: dp = [0] * 121 for i in ages: dp[i] += 1 ans = 0 mp = {} for i in range(15, 121): p = 0 if dp[i] > 0: if i % 2 == 0: Min = int(i / 2 + 8) else: Min = int(math.ceil(i / 2 + 7)) Max = i j = Min while j <= Max and j <= 120: if j == i: ans += dp[j] * (dp[j] - 1) p += dp[j] * (dp[j] - 1) else: ans += dp[i] * dp[j] p += dp[i] * dp[j] j += 1 mp[i] = p return ans
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: age_dic = {age: ages.count(age) for age in range(1, 121)} pairs = 0 for A in range(1, 121): for B in range(1, 121): if B <= 0.5 * A + 7: continue elif B > A: continue elif B > 100 and A < 100: continue else: pairs += age_dic[A] * age_dic[B] if A == B: pairs -= age_dic[A] return pairs
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def check(self, a, b): if b <= 0.5 * a + 7: return False if b > a: return False if b > 100 and a < 100: return False return True def numFriendRequests(self, ages: List[int]) -> int: cnt = 0 c = [(0) for x in range(121)] for a in ages: c[a] += 1 for i in range(len(c)): for j in range(len(c)): if self.check(i, j): cnt += c[i] * c[j] if i == j: cnt -= c[i] return cnt
CLASS_DEF FUNC_DEF IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def B_search(self, nums, target): low, high = 0, len(nums) - 1 while low < high: mid = low + (high - low) // 2 if nums[mid] < target: low = mid + 1 else: high = mid return high def numFriendRequests(self, ages: List[int]) -> int: ages.sort() count = 0 for age in ages: left = self.B_search(ages, int(0.5 * age + 7) + 1) right = self.B_search(ages, age + 1) if right == len(ages) - 1 and ages[right] == age: right += 1 if ages[left] == 0.5 * age + 7: left += 1 count += max(0, right - left - 1) return count
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: def request(a, b): return not (b <= 0.5 * a + 7 or b > a or b > 100 and a < 100) c = collections.Counter(ages) return sum(request(a, b) * c[a] * (c[b] - (a == b)) for a in c for b in c)
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF RETURN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: counter = Counter(ages) ages = list(counter.keys()) res = 0 for a in ages: for b in ages: if b <= 0.5 * a + 7: continue if b > a: continue if b > 100 and a < 100: continue if a == b: res += counter[a] * (counter[a] - 1) else: res += counter[a] * counter[b] return res
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: d = {} ans = 0 for age in ages: if age not in d: d[age] = 1 else: d[age] += 1 print(d) for ageA, countA in list(d.items()): for ageB, countB in list(d.items()): print((ageA, countA, ageB, countB)) if ageA * 0.5 + 7 >= ageB: continue if ageA < ageB: continue if ageA < 100 < ageB: continue if ageA != ageB: ans += countA * countB else: ans += (countA - 1) * countA return ans
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR IF VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: def friendRequests(age_a, age_b): if age_b <= 0.5 * age_a + 7 or age_b > age_a: return False return True age_groups = collections.Counter(ages) total_requests = 0 for age_a, count_a in list(age_groups.items()): for age_b, count_b in list(age_groups.items()): if friendRequests(age_a, age_b): total_requests += count_a * count_b if age_a == age_b: total_requests -= count_a return total_requests
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: count = [0] * 121 s = [0] * 121 for a in ages: count[a] += 1 for i in range(1, 121): s[i] = s[i - 1] + count[i] res = 0 for i in range(15, 121): edge = i // 2 + 7 num = s[i] - s[edge] res += count[i] * num - count[i] return res
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: ages.sort() res = 0 i = 0 while i < len(ages): if ages[i] <= 14: i += 1 else: break if i == len(ages): return 0 leftmost = i for i in range(leftmost, len(ages)): left, right = leftmost, i - 1 edge = ages[i] * 0.5 + 7 while left <= right: m = (left + right) // 2 if ages[m] <= edge: left = m + 1 else: right = m - 1 res += i - left left, right = i + 1, len(ages) - 1 while left <= right: m = (left + right) // 2 if ages[m] <= ages[i]: left = m + 1 else: right = m - 1 left -= 1 res += left - i return res
CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: ages = sorted(ages) print(ages) def bound(a): low = a // 2 + 8 hi = a return min(low, a), hi def getlow(v): lo, hi = 0, len(ages) while lo < hi: mid = (lo + hi) // 2 if ages[mid] >= v: hi = mid else: lo = mid + 1 return hi def getupper(v): lo, hi = 0, len(ages) while lo < hi: mid = (lo + hi) // 2 if ages[mid] <= v: lo = mid + 1 else: hi = mid return hi - 1 count = 0 for i in range(len(ages)): if ages[i] <= 14: continue minv, maxv = bound(ages[i]) c = getupper(maxv) - getlow(minv) count += c p = 115 return count
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: def invert(a): return -1 * a ages.sort(key=invert) age_request_map = collections.defaultdict(int) num_requests = 0 for age in ages: if age <= 14: break num_requests += age_request_map[age] age_request_map[age] += 1 lowest_age = floor(age * 0.5 + 7) + 1 for i in range(lowest_age, age + 1): age_request_map[i] += 1 return num_requests
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF RETURN BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: counts = Counter(ages) requests = 0 conditions = [ lambda ageA, ageB: 0.5 * ageA + 7 >= ageB, lambda ageA, ageB: ageA < ageB, ] def canSendRequest(ageA, ageB): return not any(condition(ageA, ageB) for condition in conditions) for ageA, countA in counts.items(): for ageB, countB in counts.items(): if canSendRequest(ageA, ageB): if ageA == ageB: requests += countA * (countA - 1) else: requests += countA * countB return requests
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: count = collections.Counter(ages) ans = 0 for A, countA in count.items(): for B, countB in count.items(): if B <= 0.5 * A + 7: continue elif B > A: continue elif B > 100 and A < 100: continue ans += countA * countB if A == B: ans -= countA return ans
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR IF VAR VAR VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: age_library = {} for age in ages: age_library[age] = age_library.get(age, 0) + 1 res = 0 for A, numA in list(age_library.items()): for B, numB in list(age_library.items()): if not (B <= 0.5 * A + 7 or B > A or B > 100 and A < 100): res += numA * numB - numA * (A == B) return res
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: counter = [0] * 121 res = 0 for a in ages: if a <= 14: continue counter[a] += 1 for i in range(15, 121): for j in range(i + 1): if j <= 0.5 * i + 7: continue res += counter[i] * counter[j] if i == j: res -= counter[i] return res
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: ageCounts = Counter(ages) numRequests = 0 for a in range(1, 121): if ageCounts[a] > 0: exclLowerBound = 0.5 * a + 7 lowerBound = ceil(exclLowerBound) if lowerBound == exclLowerBound: lowerBound += 1 for a2 in range(lowerBound, a): numRequests += ageCounts[a2] * ageCounts[a] if lowerBound <= a: numRequests += ageCounts[a] * (ageCounts[a] - 1) return numRequests
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: sum = 0 counts = collections.Counter(ages) ages = sorted(counts.keys()) for A in range(0, len(ages)): for B in range(0, len(ages)): condition1 = ages[B] <= 0.5 * ages[A] + 7 condition2 = ages[B] > ages[A] condition3 = ages[B] > 100 and ages[A] < 100 if not (condition1 or condition2 or condition3): if A != B: sum += counts[ages[A]] * counts[ages[B]] else: sum += (counts[ages[A]] - 1) * counts[ages[B]] return sum
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: def req(A, B): if B <= 0.5 * A + 7 or B > A or B > 100 and A < 100: return False return True cnt = Counter(ages) ans = 0 for i in cnt: if cnt[i] > 1 and req(i, i): ans += cnt[i] * (cnt[i] - 1) for j in cnt: if i != j and req(i, j): ans += cnt[i] * cnt[j] return ans
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER FOR VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: counts = [0] * 121 for age in ages: counts[age] += 1 SUM = 0 sums = [] for c in counts: SUM += c sums.append(SUM) res = 0 for age in range(15, 121): up = age down = age // 2 + 7 res += counts[age] * (sums[up] - sums[down] - 1) return res
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: a = sorted(ages) i, j, k = 0, 0, 0 ans = 0 for i in range(1, len(a)): if a[i] <= 14: continue lb = a[i] * 0.5 + 7 while a[j] <= lb: j += 1 ans += i - j if a[k] != a[i]: k = i ans += i - k return ans
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: age_count = Counter(ages) distinct_ages = set(age_count.keys()) total_req = 0 for a_age in distinct_ages: a_frn_req = 0 for b_age in distinct_ages: if b_age > a_age or a_age < 100 < b_age or b_age <= 0.5 * a_age + 7: continue a_frn_req += age_count[a_age] * age_count[b_age] if a_age == b_age: a_frn_req -= age_count[a_age] total_req += a_frn_req return total_req
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: if ages == []: return 0 ages.sort() res = 0 for i in range(len(ages) - 1, -1, -1): if ages[i] < 15: break age = ages[i] left = self.binary_search_left(ages, 0, i, age // 2 + 8) right = self.binary_search_right(ages, i, len(ages) - 1, age) res += max(0, right - left) return res def binary_search_left(self, ages, start, end, target): while start + 1 < end: mid = (start + end) // 2 if ages[mid] < target: start = mid else: end = mid if ages[start] >= target: return start if ages[end] >= target: return end return -1 def binary_search_right(self, ages, start, end, target): while start + 1 < end: mid = (start + end) // 2 if ages[mid] <= target: start = mid else: end = mid if ages[end] <= target: return end if ages[start] <= target: return start return -1
CLASS_DEF FUNC_DEF VAR VAR IF VAR LIST RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR RETURN VAR VAR FUNC_DEF WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR RETURN VAR IF VAR VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR RETURN VAR IF VAR VAR VAR RETURN VAR RETURN NUMBER
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: age_cnt = [0] * 121 for age in ages: age_cnt[age] += 1 res = 0 for ageA, cntA in enumerate(age_cnt): for ageB, cntB in enumerate(age_cnt): if ageB <= 0.5 * ageA + 7 or ageB > ageA or ageB > 100 and ageA < 100: continue res += cntA * cntB if ageA == ageB: res -= cntA return res
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR IF VAR VAR VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: ages.sort() ans, i, j = 0, 0, 0 while i < len(ages): val = ages[i] while j < i and ages[j] <= 0.5 * val + 7: j += 1 cnt, num_equal = i - j, 0 while i < len(ages) and ages[i] == val: num_equal, i = num_equal + 1, i + 1 ans += num_equal * cnt + num_equal * (num_equal - 1) return ans def numFriendRequests(self, ages): count = [0] * 121 for age in ages: count[age] += 1 ans = 0 for ageA, countA in enumerate(count): for ageB, countB in enumerate(count): if ageA * 0.5 + 7 >= ageB: continue if ageA < ageB: continue ans += countA * countB if ageA == ageB: ans -= countA return ans
CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR RETURN VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: ages = sorted(ages) count, temp_count = 0, 0 for i in range(len(ages) - 1, -1, -1): if i + 1 < len(ages) and ages[i + 1] == ages[i]: count += temp_count continue temp_count, current = 0, i - 1 age = 0.5 * ages[i] + 7 while current >= 0 and ages[current] > age: temp_count += 1 current = current - 1 count = count + temp_count return count
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: cnt = collections.Counter(ages) ans = 0 for age in ages: cnt[age] -= 1 left, right = age // 2 + 8, age ans += sum(cnt[age] for age in range(left, right + 1)) cnt[age] += 1 return ans
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: count = [0] * 121 max_age = 0 for age in ages: count[age] += 1 max_age = max(max_age, age) ans = 0 for ageA, countA in enumerate(count[: max_age + 2]): for ageB, countB in enumerate(count[: max_age + 2]): if ageA * 0.5 + 7 >= ageB: continue if ageA < ageB: continue if ageA < 100 < ageB: continue ans += countA * countB if ageA == ageB: ans -= countA return ans
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: if not ages: return 0 agesToCount = [0] * 121 for age in ages: agesToCount[age] += 1 result = 0 for ageA in range(1, 121): for ageB in range(1, 121): if ageB <= ageA and ageB > 0.5 * ageA + 7: if ageA == ageB: result += agesToCount[ageA] * (agesToCount[ageA] - 1) else: result += agesToCount[ageA] * agesToCount[ageB] return result
CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: buckets = [0] * 121 for age in ages: buckets[age] += 1 ans = 0 for i in range(1, 121): if buckets[i] <= 0: continue for j in range(1, 121): if buckets[j] <= 0: continue if j <= 0.5 * i + 7 or j > i or j > 100 and i < 100: continue ans += buckets[i] * buckets[j] if i == j: ans -= buckets[i] return ans
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR VAR VAR RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: def wantToRequest(A, B): return not (B <= 0.5 * A + 7 or B > A) count = Counter(ages) ans = 0 ages = [*sorted(count.keys())] for i, a in enumerate(ages): for j in range(0, i + 1): b = ages[j] if wantToRequest(a, b): ans += count[a] * count[b] if a != b else count[a] * (count[b] - 1) return ans
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF RETURN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: count = [0] * 121 for a in ages: count[a] += 1 for i, val in enumerate(count): count[i] = count[i - 1] + val total = 0 for a in ages: ageMin = floor(0.5 * a + 8) ageMax = min(a, 120) ageMin = max(ageMin - 1, 0) total += max(count[ageMax] - count[ageMin] - 1, 0) return total
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def numFriendRequests(self, ages: List[int]) -> int: if not ages: return 0 freq = Counter(ages) def can_request(a, b): return not (b <= 0.5 * a + 7 or b > a or b > 100 and a < 100) ans = 0 for a1 in range(1, 121): for a2 in range(1, 121): if can_request(a1, a2): ans += ( freq[a1] * freq[a2] if a1 != a2 else freq[a1] * (freq[a1] - 1) ) return ans
CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER RETURN VAR VAR
Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of the following conditions are true: age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 Otherwise, A will friend request B. Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves. How many total friend requests are made? Example 1: Input: [16,16] Output: 2 Explanation: 2 people friend request each other. Example 2: Input: [16,17,18] Output: 2 Explanation: Friend requests are made 17 -> 16, 18 -> 17. Example 3: Input: [20,30,100,110,120] Output: 3 Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.   Notes: 1 <= ages.length <= 20000. 1 <= ages[i] <= 120.
class Solution: def firstLTE(self, lowerBound, ages, endIndex): if endIndex < 0: return 0 l = 0 r = endIndex while l < r: m = (l + r) // 2 if ages[m] <= lowerBound: l = m + 1 else: r = m if l <= r and ages[l] > lowerBound: return l return endIndex + 1 def findEarliest(self, key, ages, endIndex): if endIndex < 0: return -1 l = 0 r = endIndex while l < r: m = (l + r) // 2 if ages[m] >= key: r = m else: l = m + 1 if l <= endIndex and ages[l] == key: return l return -1 def numFriendRequests(self, ages: List[int]) -> int: if not ages: return 0 numRequests = 0 ages.sort() for i, a in enumerate(ages): lowerBound = a * 0.5 + 7 startIndex = self.firstLTE(lowerBound, ages, i - 1) numRequests += i - startIndex if a > lowerBound: startIndex = self.findEarliest(a, ages, i - 1) if startIndex >= 0 and startIndex < i: numRequests += i - startIndex return numRequests
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR VAR VAR RETURN VAR RETURN BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF VAR VAR IF VAR RETURN NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR