結果
| 問題 |
No.694 square1001 and Permutation 3
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-06-09 20:18:52 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,045 bytes |
| コンパイル時間 | 139 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 65,652 KB |
| 最終ジャッジ日時 | 2024-06-30 12:59:40 |
| 合計ジャッジ時間 | 11,133 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 3 RE * 9 TLE * 1 |
ソースコード
from sys import stdin
from bisect import bisect, bisect_left
class BIT:
def __init__(self, n):
self.size = n
self.bit = [0] * (n + 1)
def add(self, i, x):
'add c to the value at index i'
while i <= self.size:
self.bit[i] += x
i += i & -i
def sum(self, i):
'get sum from the start to the index of i'
ret = 0
while i > 0:
ret += self.bit[i]
i -= i & -i
return ret
def range_sum(self, start, end):
'Calculate a[start], a[start+1], ... a[end]'
return self.sum(end) - self.sum(start - 1)
def __str__(self):
return str(self.bit)
def main():
N = int(input())
A = list(map(int, stdin.read().splitlines()))
ans = 0
bit = BIT(N)
for i, v in enumerate(A):
ans += i - bit.sum(v)
bit.add(v, 1)
print(ans)
num = sorted(A)
for i in range(N - 1):
ans -= bisect_left(num, A[i])
ans += N - bisect(num, A[i])
print(ans)
main()