QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#556545#9238. TreeXun_xiaoyao0 45ms22036kbC++17999b2024-09-10 19:17:592024-09-10 19:17:59

Judging History

你现在查看的是最新测评结果

  • [2024-09-10 19:17:59]
  • 评测
  • 测评结果:0
  • 用时:45ms
  • 内存:22036kb
  • [2024-09-10 19:17:59]
  • 提交

answer

#include <bits/stdc++.h>
#include "tree.h"
using namespace std;

int fa[200010];
int get_fa(int a){return a==fa[a]?a:fa[a]=get_fa(fa[a]);}

int n,w[200010],siz[200010];
vector<int> son[200010];
long long a[200010],b[200010];
int ccf[200010],cf[200010],f[200010];
vector<int> nd;
void init(std::vector<int> P, std::vector<int> W)
{
	n=W.size();
	for(int i=2;i<=n;i++) son[P[i-1]+1].push_back(i);
	for(int i=1;i<=n;i++) w[i]=W[i-1];

	for(int i=1;i<=n;i++)
	{
		if(son[i].empty()) f[n+1]+=w[i];
		else nd.push_back(i);
		fa[i]=i,siz[i]=1;
	}
	sort(nd.begin(),nd.end(),[&](int a,int b){return w[a]>w[b];});
	for(int g:nd)
	{
		int u=get_fa(g);
		ccf[siz[u]]-=w[g];
		for(int v:son[g])
		{
			fa[v]=u,siz[u]+=siz[v];
			ccf[siz[v]]+=w[v]-w[g],ccf[1]-=w[v]-w[g];
		}
		ccf[siz[u]]=w[g];
	}
	for(int i=n;i;i--) cf[i]=cf[i+1]+ccf[i];
	for(int i=n;i;i--) f[i]=f[i+1]+cf[i];
}

long long query(int L, int R)
{
	int k=min(R/L,n);
	return f[k+2]*L-cf[k+1]*(R-k*L);
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 30ms
memory: 21280kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 0 2 2 4 5 4 5 8 9 10 9 8 10 14 15 14 15 18 19 20 21 18 22 21 24 24 27 22 27 30 31 31 33 30 19 20 33 38 38 40 41 41 43 44 43 44 47 48 49 50 49 50 53 54 53 48 54 58 58 60 60 62 62 64 64 66 66 67 67 70 71 72 71 72 75 70 75 78 78 80 81 80 81 84 85 86 86 88 89 90...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
131170797
43053797
-758124293
-626217931
2035672091
420491932
-808821007
-439584815
-46872875
-1923831999

result:

wrong answer 3rd lines differ - on the 1st token, expected: '682654248246', found: '131170797'

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 3ms
memory: 12104kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
2000
0 0 1 1 4 4 6 7 6 7 10 10 12 12 14 15 14 15 18 19 19 21 18 21 24 24 26 27 26 27 30 30 32 32 34 34 36 37 38 39 39 41 37 38 36 41 46 47 48 47 48 51 51 53 54 54 56 56 58 58 60 61 61 63 64 64 66 67 66 67 70 71 72 72 74 75 76 76 75 74 70 77 63 60 77 85 85 87 87 89 89...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
-961553904
1931638108
-1605432404
2016532736
1161666066
2031104344
-113637768
2143757978
1919301264
997527530

result:

wrong answer 3rd lines differ - on the 1st token, expected: '175909322571', found: '-961553904'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #33:

score: 0
Wrong Answer
time: 45ms
memory: 22036kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 1 0 1 2 2 6 6 7 7 10 11 11 13 14 13 14 17 10 17 20 21 22 22 23 21 20 23 28 29 28 29 32 33 34 32 33 34 38 39 39 40 42 42 44 45 46 47 48 45 46 48 52 53 53 54 56 56 58 58 60 61 62 63 63 65 61 66 62 66 70 71 71 72 72 75 60 65 75 79 52 44 70 47 40 54 79 87 87 89 ...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
-1549514304
2016282970
-79235802
651396112
-378497895
-381603979
-307904244
20819981
1713492053
-142535332
247109507
438203522
1465972334
8810006
-209796960
-283606162
-1490684347
-1818769069
83088788
1225306321
688655149
1490485630
172150752
608821444
-43525373
2...

result:

wrong answer 3rd lines differ - on the 1st token, expected: '18330254280', found: '-1549514304'

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Wrong Answer

Test #47:

score: 0
Wrong Answer
time: 31ms
memory: 21336kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 1 0 1 4 5 5 7 7 9 9 11 12 13 13 11 14 12 14 19 20 19 20 23 24 25 26 26 28 28 30 31 32 33 33 35 35 30 32 31 37 41 42 43 24 44 46 46 48 49 50 51 51 53 54 55 55 56 56 48 50 54 44 59 49 25 59 67 68 67 68 71 71 72 72 75 76 76 78 79 80 37 80 83 83 85 86 85 79 41 8...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
1487980782
1239911204
-984884637
-1030501144
1196604644
1852473934
-1872335850
-2113293486
-1495505471
1037949014
1451826356
1650382826
1041953016
-1074473386
2101720468
-1479275496
1326565146
-1038645315
-1768707528
-78240512
-1807577522
-1895803301
-1707950535
1...

result:

wrong answer 3rd lines differ - on the 1st token, expected: '44399242169', found: '1487980782'

Subtask #7:

score: 0
Skipped

Dependency #1:

0%