結果
問題 |
No.696 square1001 and Permutation 5
|
ユーザー |
![]() |
提出日時 | 2025-06-12 20:47:50 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,001 bytes |
コンパイル時間 | 164 ms |
コンパイル使用メモリ | 82,448 KB |
実行使用メモリ | 96,236 KB |
最終ジャッジ日時 | 2025-06-12 20:49:22 |
合計ジャッジ時間 | 1,730 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 1 WA * 11 |
ソースコード
MOD = 10**9 + 7 class FenwickTree: def __init__(self, size): self.size = size self.tree = [0] * (size + 2) def update(self, index, delta): while index <= self.size: self.tree[index] += delta index += index & -index def query(self, index): res = 0 while index > 0: res += self.tree[index] index -= index & -index return res def main(): import sys input = sys.stdin.read().split() N = int(input[0]) p = list(map(int, input[1:N+1])) fact = [1] * (N + 1) for i in range(1, N+1): fact[i] = fact[i-1] * i % MOD ft = FenwickTree(N) total = 0 for i in range(N-1, -1, -1): current = p[i] smaller = ft.query(current - 1) term = smaller * fact[N - i - 1] % MOD total = (total + term) % MOD ft.update(current, 1) ans = (total + 1) % MOD print(ans) if __name__ == "__main__": main()