結果
| 問題 |
No.696 square1001 and Permutation 5
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 14:34:06 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 834 bytes |
| コンパイル時間 | 309 ms |
| コンパイル使用メモリ | 81,984 KB |
| 実行使用メモリ | 280,280 KB |
| 最終ジャッジ日時 | 2025-06-12 14:34:47 |
| 合計ジャッジ時間 | 32,674 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 RE * 7 |
ソースコード
class FenwickTree:
def __init__(self, size):
self.n = size
self.tree = [0] * (self.n + 1) # 1-based indexing.
def update(self, idx, delta=1):
while idx <= self.n:
self.tree[idx] += delta
idx += idx & -idx
def query(self, idx):
res = 0
while idx > 0:
res += self.tree[idx]
idx -= idx & -idx
return res
def main():
import sys
input = sys.stdin.read().split()
n = int(input[0])
p = list(map(int, input[1:n+1]))
ft = FenwickTree(n)
current_fact = 1
total = 0
for i in range(n-1, -1, -1):
x = p[i]
m = ft.query(x - 1)
total += m * current_fact
ft.update(x)
current_fact *= (n - i)
print(total + 1)
if __name__ == "__main__":
main()
gew1fw