結果
| 問題 | No.778 クリスマスツリー |
| コンテスト | |
| ユーザー |
kriii
|
| 提出日時 | 2018-12-25 00:04:31 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 622 bytes |
| 記録 | |
| コンパイル時間 | 337 ms |
| コンパイル使用メモリ | 48,896 KB |
| 実行使用メモリ | 22,464 KB |
| 最終ジャッジ日時 | 2024-09-25 11:06:13 |
| 合計ジャッジ時間 | 6,801 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | TLE * 1 -- * 2 |
| other | -- * 12 |
ソースコード
#include <stdio.h>
#include <vector>
using namespace std;
int B[200200];
int N,P[200200];
vector<int> G[200200];
long long ans;
void in(int x, int p)
{
while (x <= N){
B[x] += p;
x += x & (-x);
}
}
int out(int x)
{
int r = 0;
while (x){
r += B[x];
x -= x & (-x);
}
return r;
}
void go(int x){
ans += out(x);
in(x,1);
for (auto y : G[x]) go(y);
in(x,-1);
}
int main()
{
scanf ("%d",&N);
for (int i=1;i<N;i++){
scanf ("%d",&P[i]);
G[P[i]].push_back(i);
}
go(0);
printf ("%lld\n",ans);
return 0;
}
kriii