結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
ユーザー convexineqconvexineq
提出日時 2021-03-19 03:22:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 109 ms / 2,500 ms
コード長 1,070 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 80,768 KB
最終ジャッジ日時 2024-04-28 16:58:04
合計ジャッジ時間 2,011 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,096 KB
testcase_01 AC 43 ms
52,480 KB
testcase_02 AC 43 ms
52,608 KB
testcase_03 AC 43 ms
52,224 KB
testcase_04 AC 44 ms
52,992 KB
testcase_05 AC 48 ms
59,520 KB
testcase_06 AC 53 ms
61,056 KB
testcase_07 AC 70 ms
66,176 KB
testcase_08 AC 66 ms
72,004 KB
testcase_09 AC 39 ms
52,224 KB
testcase_10 AC 40 ms
51,968 KB
testcase_11 AC 109 ms
80,768 KB
testcase_12 AC 96 ms
80,256 KB
testcase_13 AC 39 ms
51,968 KB
testcase_14 AC 40 ms
52,224 KB
testcase_15 AC 41 ms
51,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# Your code here!
"""
Binary indexed tree
0-indexed, 関数は閉区間
0からの区間加算、1点更新
"""
class BIT: #0-indexed
    def __init__(self, n):
        self.tree = [0]*(n+1)
        self.tree[0] = None
#        self.element = [0]*(n+1)
    def sum(self, i): #a_0 + ... + a_{i} #閉区間
        s = 0; i += 1
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
    def range(self,l,r): #a_l + ... + a_r 閉区間
        return sum(r) - sum(l-1) 
    def add(self, i, x):
        i += 1
        while i <= n:
            self.tree[i] += x
            i += i & -i
        # self.element[i] += x
    #def get(self,i): return element[i]        
    
###########################################
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,*a = map(int,open(0).read().split())

sA = sorted(a)
b = BIT(n)
from bisect import *
ans = 0
for i,ai in enumerate(a):
    j = bisect_left(sA, ai)
    ans += i - b.sum(j)
    b.add(j,1)

print(ans)
0