結果

問題 No.778 クリスマスツリー
ユーザー むらためむらため
提出日時 2019-01-30 00:23:40
言語 Nim
(2.0.2)
結果
RE  
実行時間 -
コード長 1,378 bytes
コンパイル時間 3,120 ms
コンパイル使用メモリ 66,864 KB
実行使用メモリ 27,936 KB
最終ジャッジ日時 2023-09-14 03:12:49
合計ジャッジ時間 4,931 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 45 ms
27,704 KB
testcase_07 AC 17 ms
6,368 KB
testcase_08 RE -
testcase_09 AC 90 ms
10,452 KB
testcase_10 AC 90 ms
10,572 KB
testcase_11 AC 88 ms
10,444 KB
testcase_12 AC 83 ms
10,440 KB
testcase_13 AC 31 ms
9,608 KB
testcase_14 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport]

ソースコード

diff #

import sequtils
import times
template stopwatch(body) = (let t1 = cpuTime();body;echo "TIME:",(cpuTime() - t1) * 1000,"ms")
template stopwatch(body) = body
proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int32 =
  while true:
    let k = getchar_unlocked()
    if k < '0': return
    result = 10.int32 * result + k.ord.int32 - '0'.ord.int32

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[int32]]
var bit : BinaryIndexedTree[200010,int32]
stopwatch:
  for i in 1.int32..<n.int32: E[scan()] &= i
  proc solve(x:int32): int32 =
    result += bit[x]
    bit.update(x, 1)
    for e in E[x]: result += solve(e)
    bit.update(x, -1)
  stopwatch:
    echo solve(0)
0