from typing import List, Generic, Optional, Callable, TypeVar S = TypeVar('S') class FunctionalGraph(Generic[S]): def __init__(self, n: int, edge_to: List[S], node_val: Optional[List[S]] = None, op: Callable[[int, int], int] = lambda fr, to: to) -> None: if node_val is None: node_val = list(range(n)) self.n = n self.edge_to = edge_to self.node_val = node_val self.op = op self.built = False def build_doubling(self, bit_max: int = 31): self.built = True self.bit_max = bit_max self.dub = [[-1] * self.n for _ in range(self.bit_max)] self.dp = [[-1] * self.n for _ in range(self.bit_max)] for i in range(self.n): self.dub[0][i] = self.edge_to[i] self.dp[0][i] = self.node_val[i] # node_valを1回移動後の値にする? for i in range(1, self.bit_max): for j in range(self.n): if self.dub[i - 1][j] != -1: self.dub[i][j] = self.dub[i - 1][self.dub[i - 1][j]] self.dp[i][j] = self.op(self.dp[i - 1][j], self.dp[i - 1][self.dub[i - 1][j]]) def get(self, v: int, k: int) -> int: if not self.built: self.build_doubling() for i in range(self.bit_max): if k & (1 << i): v = self.dub[i][v] return v def prod(self, v: int, k: int) -> S: if not self.built: self.build_doubling() res = v # 要修正! for i in range(self.bit_max): if k & (1 << i): res = self.op(res, self.dp[i][v]) v = self.dub[i][v] return res N, K = map(int, input().split()) P = list(map(int, input().split())) edge_to = [(i + P[i]) % N for i in range(N)] node_val = [0] * N for i in range(N): node_val[i] = i + P[i] def op(fr, to): return to + fr // N * N F = FunctionalGraph(N, edge_to, node_val, op) F.build_doubling(4) for i in range(N): res = F.prod(i, K) print(res + 1)