結果

問題 No.696 square1001 and Permutation 5
ユーザー beet
提出日時 2018-06-09 00:20:54
言語 PyPy3
(7.3.15)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 689 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 82,428 KB
実行使用メモリ 267,400 KB
最終ジャッジ日時 2024-06-30 11:48:16
合計ジャッジ時間 36,253 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 5 RE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

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

    bit = list(map(int, [0 for i in range(n+1)]))
    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
    buf = 0
    x = 1
    for i in range(1, n+1):
        t = x * sum(p[n-i])
        buf = t + buf
        if i & 16383 == 0:
            ans = buf + ans
            buf = 0
        add(p[n-i], 1)
        x = x * i

    print(ans + buf)
    
main()
0