結果
| 問題 | No.694 square1001 and Permutation 3 | 
| コンテスト | |
| ユーザー |  6soukiti29 | 
| 提出日時 | 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,algorithm
import sequtils,strutils
type
    binaryIndexTree[I:static[int]] = array[I + 1,int]
proc add(BIT :var binaryIndexTree,i : int, a : int)=
    var index = i
    while BIT[0] >= index:
        BIT[index] += a
        index += ((index xor (index - 1)) and index)
proc sum(BIT : binaryIndexTree, i : int):int =
    var index = i
    while index > 0:
        result += BIT[index]
        index = (index and (index - 1))
var
    BIT : binaryIndexTree[500010]
    N = stdin.readline.parseInt
    A = newSeq[int](0)
    B : seq[int]
    a,s : int
    ans : int
for n in 0..<N:
    a = stdin.readline.parseInt
    A.add(a)
B = A.sorted(system.cmp)
for n in 0..<N:
    A[n] = B.lowerBound(A[n]) + 1
BIT[0] = 500010
for n in 0..<N:
    a = n - BIT.sum(A[n])
    s += a
    BIT.add(A[n], 1)
echo s
for i in A[0..<A.high]:
    s -= BIT.sum(i - 1)
    s += N - BIT.sum(i)
    echo s
    
            
            
            
        