結果

問題 No.694 square1001 and Permutation 3
ユーザー GrayCoderGrayCoder
提出日時 2018-06-10 08:41:53
言語 PyPy3
(7.3.15)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 835 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 257,848 KB
最終ジャッジ日時 2023-09-13 02:33:52
合計ジャッジ時間 10,620 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,248 KB
testcase_01 AC 75 ms
71,360 KB
testcase_02 AC 76 ms
71,416 KB
testcase_03 AC 89 ms
75,888 KB
testcase_04 AC 92 ms
75,932 KB
testcase_05 AC 90 ms
75,900 KB
testcase_06 AC 92 ms
75,972 KB
testcase_07 AC 790 ms
182,672 KB
testcase_08 AC 1,207 ms
200,996 KB
testcase_09 MLE -
testcase_10 AC 778 ms
182,336 KB
testcase_11 MLE -
testcase_12 MLE -
testcase_13 AC 76 ms
71,416 KB
権限があれば一括ダウンロードができます

ソースコード

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()))

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

    num = sorted(A)
    for i in range(1, N):
        ans[i] = ans[i-1] - bisect_left(num, A[i-1])
        ans[i] += N - bisect(num, A[i-1])

    print(*ans, sep='\n')

main()
0