結果

問題 No.1604 Swap Sort:ONE
ユーザー tcltktcltk
提出日時 2021-10-19 06:46:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 1,010 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 81,864 KB
実行使用メモリ 88,684 KB
最終ジャッジ日時 2023-10-20 10:12:43
合計ジャッジ時間 4,994 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
86,024 KB
testcase_01 AC 123 ms
86,024 KB
testcase_02 AC 128 ms
86,024 KB
testcase_03 AC 124 ms
86,024 KB
testcase_04 AC 124 ms
86,024 KB
testcase_05 AC 139 ms
88,660 KB
testcase_06 AC 140 ms
88,640 KB
testcase_07 AC 142 ms
88,668 KB
testcase_08 AC 144 ms
88,680 KB
testcase_09 AC 143 ms
88,672 KB
testcase_10 AC 142 ms
88,664 KB
testcase_11 AC 140 ms
88,668 KB
testcase_12 AC 141 ms
88,664 KB
testcase_13 AC 143 ms
88,644 KB
testcase_14 AC 140 ms
88,668 KB
testcase_15 AC 141 ms
88,668 KB
testcase_16 AC 142 ms
88,664 KB
testcase_17 AC 146 ms
88,664 KB
testcase_18 AC 140 ms
88,664 KB
testcase_19 AC 143 ms
88,632 KB
testcase_20 AC 140 ms
88,684 KB
testcase_21 AC 141 ms
88,632 KB
testcase_22 AC 139 ms
88,636 KB
testcase_23 AC 137 ms
88,136 KB
testcase_24 AC 136 ms
88,156 KB
testcase_25 AC 141 ms
88,632 KB
testcase_26 AC 139 ms
88,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)

# _INPUT = """3
# 3 2 1

# """
# sys.stdin = io.StringIO(_INPUT)

class BIT:
    def __init__(self, n):
        self.size = n
        self.data = [0] * (n+1)
        # self.depth = n.bit_length()
    def add(self, i, x):
        while i <= self.size:
            self.data[i] += x
            i += i & -i
    def get_sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def get_rsum(self, l, r):
        """
        [l, r] の sum
        """
        return self.get_sum(r) - self.get_sum(l-1)


INF = 10**10

N = int(input())
A = list(map(lambda x: int(x)-1, input().split()))


bit = BIT(N)
v = 0
for a in reversed(A):
    v += bit.get_sum(a+1)
    bit.add(a+1, 1)
    
print(v)            
0