結果
問題 | No.694 square1001 and Permutation 3 |
ユーザー |
![]() |
提出日時 | 2018-06-08 23:55:46 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 1,219 ms / 3,000 ms |
コード長 | 915 bytes |
コンパイル時間 | 4,522 ms |
コンパイル使用メモリ | 65,796 KB |
実行使用メモリ | 23,048 KB |
最終ジャッジ日時 | 2024-06-30 11:20:09 |
合計ジャッジ時間 | 12,968 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 13 |
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport] /home/judge/data/code/Main.nim(3, 8) Warning: imported and not used: 'sequtils' [UnusedImport]
ソースコード
import sequtils,strutils,algorithmimport sequtils,strutilstypebinaryIndexTree[I:static[int]] = array[I + 1,int]proc add(BIT :var binaryIndexTree,i : int, a : int)=var index = iwhile BIT[0] >= index:BIT[index] += aindex += ((index xor (index - 1)) and index)proc sum(BIT : binaryIndexTree, i : int):int =var index = iwhile index > 0:result += BIT[index]index = (index and (index - 1))varBIT : binaryIndexTree[500010]N = stdin.readline.parseIntA = newSeq[int](0)B : seq[int]a,s : intans : intfor n in 0..<N:a = stdin.readline.parseIntA.add(a)B = A.sorted(system.cmp)for n in 0..<N:A[n] = B.lowerBound(A[n]) + 1BIT[0] = 500010for n in 0..<N:a = n - BIT.sum(A[n])s += aBIT.add(A[n], 1)echo sfor i in A[0..<A.high]:s -= BIT.sum(i - 1)s += N - BIT.sum(i)echo s