結果
問題 | No.694 square1001 and Permutation 3 |
ユーザー | GrayCoder |
提出日時 | 2018-06-10 04:09:42 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 916 bytes |
コンパイル時間 | 302 ms |
コンパイル使用メモリ | 87,172 KB |
実行使用メモリ | 260,632 KB |
最終ジャッジ日時 | 2023-09-13 02:32:04 |
合計ジャッジ時間 | 10,968 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 74 ms
71,332 KB |
testcase_01 | AC | 75 ms
71,128 KB |
testcase_02 | AC | 75 ms
71,328 KB |
testcase_03 | AC | 92 ms
75,980 KB |
testcase_04 | AC | 90 ms
76,008 KB |
testcase_05 | AC | 92 ms
76,004 KB |
testcase_06 | AC | 91 ms
75,688 KB |
testcase_07 | AC | 819 ms
185,032 KB |
testcase_08 | AC | 1,219 ms
197,216 KB |
testcase_09 | MLE | - |
testcase_10 | AC | 795 ms
184,980 KB |
testcase_11 | MLE | - |
testcase_12 | MLE | - |
testcase_13 | AC | 77 ms
71,460 KB |
ソースコード
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()