結果
問題 | No.694 square1001 and Permutation 3 |
ユーザー | GrayCoder |
提出日時 | 2018-06-10 08:57:37 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 859 bytes |
コンパイル時間 | 325 ms |
コンパイル使用メモリ | 87,100 KB |
実行使用メモリ | 257,468 KB |
最終ジャッジ日時 | 2023-09-13 02:34:16 |
合計ジャッジ時間 | 10,780 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 73 ms
71,472 KB |
testcase_01 | AC | 72 ms
71,544 KB |
testcase_02 | AC | 71 ms
71,332 KB |
testcase_03 | AC | 85 ms
75,708 KB |
testcase_04 | AC | 88 ms
76,032 KB |
testcase_05 | AC | 85 ms
75,960 KB |
testcase_06 | AC | 85 ms
76,100 KB |
testcase_07 | AC | 759 ms
182,412 KB |
testcase_08 | AC | 1,172 ms
200,840 KB |
testcase_09 | MLE | - |
testcase_10 | AC | 755 ms
182,476 KB |
testcase_11 | MLE | - |
testcase_12 | MLE | - |
testcase_13 | AC | 73 ms
71,316 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())) ans = [0] * N bit = BIT(N) bit_add, bit_sum = bit.add, bit.sum 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]) + N - bisect(num, A[i-1]) print(*ans, sep='\n') main()