結果

問題 No.694 square1001 and Permutation 3
ユーザー GrayCoderGrayCoder
提出日時 2018-06-10 04:08:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 916 bytes
コンパイル時間 136 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 75,356 KB
最終ジャッジ日時 2023-09-13 02:31:45
合計ジャッジ時間 11,879 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,208 KB
testcase_01 AC 16 ms
8,044 KB
testcase_02 AC 16 ms
7,992 KB
testcase_03 AC 17 ms
8,332 KB
testcase_04 AC 17 ms
8,372 KB
testcase_05 AC 17 ms
8,416 KB
testcase_06 AC 17 ms
8,336 KB
testcase_07 AC 2,263 ms
59,076 KB
testcase_08 TLE -
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
from bisect import bisect, bisect_left

class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def sum(self, i):
        ret = 0
        while i > 0:
            ret += self.tree[i]
            i -= i & -i
        return ret

def main():
    N = int(input())
    A = list(map(int, stdin.read().splitlines()))

    if N == 1:
        print(0)
        return

    cnt = 0
    ans = []
    apnd = ans.append
    bit = BIT(N)
    a = sorted(set(A))
    for i, v in enumerate(A):
        x = bisect(a, v)
        cnt += i - bit.sum(x)
        bit.add(x, 1)
    apnd(cnt)

    num = sorted(A)
    for i in range(N - 1):
        cnt -= bisect_left(num, A[i])
        cnt += N - bisect(num, A[i])
        apnd(cnt)
    print(*ans, sep='\n')
main()
0