QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#560814#9238. Treeyyyyxh0 63ms31816kbC++231.6kb2024-09-12 18:08:222024-09-12 18:08:23

Judging History

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

  • [2024-09-12 18:08:23]
  • 评测
  • 测评结果:0
  • 用时:63ms
  • 内存:31816kb
  • [2024-09-12 18:08:22]
  • 提交

answer

#include "tree.h"
#include <algorithm>
#define ALL(vc) (vc).begin(),(vc).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=200003,INF=0x3f3f3f3f;
int n;ll L,R,dlt;
vi vec[N];
ll ans[N];int tr[N],f[N];
ll pre[N],suf[N];
int rt(int x){
	if(f[x]==x) return x;
	return f[x]=rt(f[x]);
}
int dfn[N],sz[N],num;
void dfs(int u){
	sz[u]=1;dfn[u]=++num;
	for(int v:vec[u]) dfs(v),sz[u]+=sz[v];
}
void upd(int x,int v){while(x) tr[x]+=v,x^=(x&-x);}
int qry(int x){
	ll res=0;
	while(x<=n) res+=tr[x],x+=(x&-x);
	return res;
}
int calc(int x){return qry(dfn[x])-qry(dfn[x]+sz[x]);}
void init(vi P,vi W){
	int las=0,cnt=0;num=0;
	n=P.size();dlt=0;
	vi tim(n),tp(n),del(n);
	vector<pii> seq;
	for(int i=1;i<=n;++i) tr[i]=0,ans[i]=0;
	for(int i=1;i<n;++i) vec[P[i]].emplace_back(i);
	dfs(0);
	for(int i=n-1;~i;--i){
		if(vec[i].empty()) upd(dfn[i],1),dlt+=W[i],++cnt;
		else seq.emplace_back(W[i],i);
		f[i]=i;
	}
	sort(ALL(seq),greater<pii>());
	for(auto [v,x]:seq){
		if(x&&del[P[x]]) f[x]=P[x];
		for(int i:vec[x]) if(del[i]) f[i]=x;
		del[x]=1;tp[x]=rt(x);
	}
	reverse(ALL(seq));
	for(auto [v,x]:seq){
		dlt+=(ll)(v-las)*cnt++;las=v;
		for(int i:vec[x]) tim[i]=v;
		int p=tp[x];
		ans[calc(p)]+=v-tim[p];tim[p]=v;
		int sx=calc(x);
		upd(dfn[x],1-sx);
		if(p) upd(dfn[P[p]],sx-1);
	}
	for(int i=0;i<n;++i) ans[calc(i)]+=las-tim[i];
	for(int i=1;i<=n;++i) pre[i]=pre[i-1]+i*ans[i];
	for(int i=n;i;--i) suf[i]=suf[i+1]+ans[i];
}
ll query(int _L,int _R){
	L=_L;R=_R;ll res=dlt*L;
	return res-pre[R/L]*L-suf[R/L]*R;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 51ms
memory: 30880kb

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
682654248246
834059146585
104107877065
626344246917
578222335946
1248276814116
1306128583094
417838861293
365718115496
1302019336262

result:

ok 

Test #2:

score: 10
Accepted
time: 37ms
memory: 30804kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 0 2 2 4 5 6 7 7 9 9 11 12 11 5 13 12 6 4 13 20 21 20 21 24 25 25 27 28 27 28 29 32 32 34 35 36 36 37 34 39 41 39 35 37 42 41 42 48 48 50 50 52 52 54 54 56 57 58 58 56 59 59 63 63 65 66 65 57 66 70 70 72 73 73 75 72 75 78 78 80 80 81 83 83 84 81 29 24 84 90 9...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
2412828
1922117
1327147
965330
1085799
1564240
1690944
1688948
2415056
1441542

result:

ok 

Test #3:

score: 0
Wrong Answer
time: 57ms
memory: 26584kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 0 0 3 4 5 4 4 5 5 10 10 10 13 13 15 15 15 18 3 5 5 18 23 24 24 25 27 27 27 27 31 32 33 32 33 33 33 38 38 38 41 41 38 32 38 38 41 48 48 50 50 50 53 53 55 55 55 48 55 60 60 55 61 64 64 64 64 53 64 55 64 72 72 72 50 48 72 78 78 80 81 81 81 81 83 86 86 86 86 88 ...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
33132015629125918
13893873795019119
19946610757728
612378945351184
5805050624249868
24375661619556703
21685117005989279
27623263044222663
18169686485050308
12956499749658231

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 2ms
memory: 8092kb

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
175687795619
633092729058
815015543445
39628599358
1034961926702
610225890050
164266978676
32364480884
128285899740
267574128962

result:

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

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #33:

score: 0
Wrong Answer
time: 63ms
memory: 31816kb

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
18330254280
114566555886
5123993634
1571790384
1390661403
102887513647
12142338294
532135751
48879256279
74804356884
7047438873
58553215238
26812191362
41269971650
32111371952
8116162880
57784940023
106724111433
93322831828
42829869427
28126687591
28123313538
1525...

result:

wrong answer 53559th lines differ - on the 1st token, expected: '159996', found: '-49817714518'

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Wrong Answer

Test #47:

score: 0
Wrong Answer
time: 42ms
memory: 30944kb

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
44399163403
44211911222
45790425081
45754725639
44179711430
44674585890
45108693777
44925019039
45397291905
44060527531
44371573084
44521627931
44063291895
45721280891
44864062634
45409788555
44277114676
45748924291
45187612563
46493996028
45158076131
45090650309
...

result:

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

Subtask #7:

score: 0
Skipped

Dependency #1:

0%