結果

問題 No.696 square1001 and Permutation 5
ユーザー beetbeet
提出日時 2018-06-09 00:24:42
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 679 bytes
コンパイル時間 417 ms
コンパイル使用メモリ 86,760 KB
実行使用メモリ 97,236 KB
最終ジャッジ日時 2023-09-13 00:59:01
合計ジャッジ時間 3,645 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 76 ms
75,640 KB
testcase_02 AC 76 ms
75,768 KB
testcase_03 AC 80 ms
76,304 KB
testcase_04 AC 82 ms
76,232 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 76 ms
75,412 KB
testcase_13 AC 75 ms
75,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    n = int(input())
    p = list(map(int,input().split()))

    bit = list(map(int, [0 for i in range(n+1)]))
    def get(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)
            
            
    
    buf = list(map(int, [0 for i in range(8192)]))
    a = 1
    for i in range(1, n+1):
        t = a * get(p[n-i])
        buf[i&8192] = t + buf[i&8192]
        add(p[n-i], 1)
        a = a * i

    ans = 1 + sum(buf)
    print(ans)
    
main()
0