結果
| 問題 |
No.778 クリスマスツリー
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-02-28 13:57:38 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 552 bytes |
| コンパイル時間 | 175 ms |
| コンパイル使用メモリ | 82,260 KB |
| 実行使用メモリ | 140,800 KB |
| 最終ジャッジ日時 | 2024-10-02 18:13:09 |
| 合計ジャッジ時間 | 5,063 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 RE * 3 |
ソースコード
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
G = {i:[] for i in range(1,N+1)}
for i in range(1,N):
a = A[i]+1
G[a].append(i+1)
k = 0
while 2**k<N:
k += 1
K = 2**k
B = [0 for _ in range(K+1)]
def update(i,x):
j = i
while j<=K:
B[j] += x
j += j&(-j)
def csum(i):
j = i
tot = 0
while j>0:
tot += B[j]
j -= j&(-j)
return tot
cnt = 0
def dfs(i):
global cnt
cnt += csum(i)
update(i,1)
for j in G[i]:
dfs(j)
update(j,-1)
dfs(1)
print(cnt)