結果

問題 No.696 square1001 and Permutation 5
ユーザー beetbeet
提出日時 2018-06-08 23:13:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 444 bytes
コンパイル時間 197 ms
コンパイル使用メモリ 10,876 KB
実行使用メモリ 70,412 KB
最終ジャッジ日時 2023-09-13 00:13:46
合計ジャッジ時間 39,844 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 126 ms
29,488 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 3,870 ms
40,760 KB
testcase_12 AC 129 ms
29,564 KB
testcase_13 AC 128 ms
70,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
n = int(input())
p = list(map(int,input().split()))

bit = np.zeros(n+1, dtype = int)
def sum(x):
    res = 0
    while x > 0:
        res = res + bit[x]
        x = x - (x&-x)
    return res

def add(x, y):
    if(x == 0):
        return
    while x <= n:
        bit[x] = bit[x] + y
        x = x + (x&-x)


ans = 1
x = 1
for i in range(1, n+1):
    ans = ans + sum(p[n-i]) * x
    add(p[n-i], 1)
    x = x * i

print(ans)
0