結果
問題 |
No.778 クリスマスツリー
|
ユーザー |
|
提出日時 | 2019-01-30 00:20:12 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 72 ms / 2,000 ms |
コード長 | 1,266 bytes |
コンパイル時間 | 2,711 ms |
コンパイル使用メモリ | 76,092 KB |
実行使用メモリ | 32,596 KB |
最終ジャッジ日時 | 2024-10-14 01:58:15 |
合計ジャッジ時間 | 3,923 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport]
ソースコード
import sequtils import times template stopwatch(body) = (let t1 = cpuTime();body;echo "TIME:",(cpuTime() - t1) * 1000,"ms") proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .} proc scan(): int = while true: let k = getchar_unlocked() if k < '0': return result = 10 * result + k.ord - '0'.ord type BinaryIndexedTree*[CNT:static[int],T] = object data: array[CNT,T] # 引数以下の部分和(Fenwick Tree) proc len*[CNT,T](bit:BinaryIndexedTree[CNT,T]): int = bit.data.len() proc update*[CNT,T](bit:var BinaryIndexedTree[CNT,T],i:int,val:T) = var i = i while i < bit.len(): bit.data[i] += val i = i or (i + 1) proc `[]`*[CNT,T](bit:BinaryIndexedTree[CNT,T],i:int): T = var i = i while i >= 0: result += bit.data[i] i = (i and (i + 1)) - 1 proc `$`*[CNT,T](bit:BinaryIndexedTree[CNT,T]): string = result = "[" for i in 0..<bit.len.min(100): result &= $(bit[i]) & ", " return result[0..result.len()-2] & (if bit.len > 100 : " ...]" else: "]") let n = scan() var E : array[200010,seq[int]] for i in 1..<n: E[scan()] &= i var bit : BinaryIndexedTree[200010,int] proc solve(x:int): int = result += bit[x] bit.update(x, 1) for e in E[x]: result += solve(e) bit.update(x, -1) echo solve(0)