結果
問題 | No.1097 Remainder Operation |
ユーザー | wai4u |
提出日時 | 2024-09-09 20:21:23 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 667 ms / 2,000 ms |
コード長 | 1,866 bytes |
コンパイル時間 | 445 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 24,548 KB |
最終ジャッジ日時 | 2024-09-09 20:21:34 |
合計ジャッジ時間 | 10,060 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
11,776 KB |
testcase_01 | AC | 36 ms
11,648 KB |
testcase_02 | AC | 36 ms
11,648 KB |
testcase_03 | AC | 34 ms
11,648 KB |
testcase_04 | AC | 34 ms
11,648 KB |
testcase_05 | AC | 35 ms
11,776 KB |
testcase_06 | AC | 35 ms
11,648 KB |
testcase_07 | AC | 96 ms
12,800 KB |
testcase_08 | AC | 92 ms
12,800 KB |
testcase_09 | AC | 92 ms
12,800 KB |
testcase_10 | AC | 91 ms
12,800 KB |
testcase_11 | AC | 90 ms
12,800 KB |
testcase_12 | AC | 611 ms
22,368 KB |
testcase_13 | AC | 628 ms
22,372 KB |
testcase_14 | AC | 626 ms
22,364 KB |
testcase_15 | AC | 658 ms
22,364 KB |
testcase_16 | AC | 613 ms
22,248 KB |
testcase_17 | AC | 611 ms
21,708 KB |
testcase_18 | AC | 667 ms
24,284 KB |
testcase_19 | AC | 648 ms
24,264 KB |
testcase_20 | AC | 608 ms
24,548 KB |
testcase_21 | AC | 646 ms
24,540 KB |
testcase_22 | AC | 635 ms
24,412 KB |
ソースコード
from typing import Sequence as Seq def argsort(a): return sorted(list(range(len(a))), key=lambda i: a[i]) def argperm(p): a = [0] * len(p) for i, j in enumerate(p): a[j] = i return a def rankify(a): return argperm(argsort(a)) import sys V = sys.version_info _39 = False _310 = False _311 = False _312 = False if V.major == 3: _39 = V.minor >= 9 _310 = V.minor >= 10 _311 = V.minor >= 11 _312 = V.minor >= 12 if _39: li = list tup = tuple dic = dict st = set ty = type else: from typing import ( List, Tuple, Type, Dict, Set, ) li = List tup = Tuple dic = Dict st = Set ty = Type li = list tup = tuple from typing import TypeVar, Generic as Gen T = TypeVar('T') from typing import Iterable as Iter from typing import Callable as Fn import sys sys.setrecursionlimit(1 << 20) def unique(a: Iter[T]) -> li[T]: return sorted(set(a)) from bisect import bisect_left as lb, bisect_right as ub if _311: from typing import Self else: Self = TypeVar('Self') inf = float('inf') def fancy(a, p): return [a[i] for i in p] class FG: w: int j: int s: li[int] # 1-indexed with centinel ws: int def __init__(self, f: li[int], x: li[int], u: int): p = [-1] * len(f) self.s = s = [0] i = 0 while p[u] == -1: p[u] = i i += 1 s.append(s[-1] + x[u]) u = f[u] j = p[u] self.j, self.w, self.ws = j, i - j, s[i] - s[j] def sum(self, k: int) -> int: j, s = self.j, self.s if k <= j: return s[k] q, r = divmod(k - j, self.w) return q * self.ws + s[j + r] def main(): n = int(input()) x = list(map(int, input().split())) f = [(i + x[i]) % n for i in range(n)] fg = FG(f, x, 0) q = int(input()) for _ in range(q): k = int(input()) print(fg.sum(k)) main()