QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#560003#9238. Treeyyyyxh#10 188ms28096kbC++231.3kb2024-09-12 11:22:432024-09-12 11:22:43

Judging History

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

  • [2024-09-12 11:22:43]
  • 评测
  • 测评结果:10
  • 用时:188ms
  • 内存:28096kb
  • [2024-09-12 11:22:43]
  • 提交

answer

#include "tree.h"
#include <cstdio>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int N=200003;
const int INF=0x3f3f3f3f;
int n,L,R;
vi vec[N];
int lc[N],rc[N],d[N];
int val[N],cap[N],tg[N];
inline void chmn(int &p,int v){if(p>v) p=v;}
void proc(int p,int v){
	if(!p) return;
	chmn(tg[p],v);
	chmn(val[p],v);
}
void pushdown(int p){
	if(tg[p]!=INF) proc(lc[p],tg[p]),proc(rc[p],tg[p]),tg[p]=INF;
}
int merge(int x,int y){
	if(!x||!y) return x|y;
	pushdown(x);pushdown(y);
	if(val[x]>val[y]) swap(x,y);
	rc[x]=merge(rc[x],y);
	if(d[rc[x]]>d[lc[x]]) swap(lc[x],rc[x]);
	d[x]=d[rc[x]]+1;
	return x;
}
vi w;ll res,sm[N];
int dfs(int u){
	if(vec[u].empty()){
		lc[u]=rc[u]=0;
		cap[u]=sm[u]=L;
		res+=(ll)L*w[u];
		val[u]=w[u];tg[u]=INF;
		return u;
	}
	else{
		int rt=0;
		sm[u]=0;
		for(int v:vec[u]) rt=merge(rt,dfs(v)),sm[u]+=sm[v];
		proc(rt,w[u]);
		while(sm[u]>R){
			pushdown(rt);
			if(cap[rt]>sm[u]-R){
				res+=(ll)(sm[u]-R)*val[rt];
				cap[rt]-=sm[u]-R;
				sm[u]=R;
			}
			else{
				res+=(ll)cap[rt]*val[rt];
				sm[u]-=cap[rt];
				rt=merge(lc[rt],rc[rt]);
			}
		}
		return rt;
	}
}
void init(vi P,vi W){
	n=P.size();w=W;
	for(int i=1;i<n;++i) vec[P[i]].emplace_back(i);
}
ll query(int _L,int _R){
	d[0]=-1;L=_L;R=_R;res=0;dfs(0);
	return res;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 75ms
memory: 28020kb

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: 100ms
memory: 28096kb

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: 10
Accepted
time: 101ms
memory: 23128kb

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
57510536913265758
13893873797083323
19946610899128
612378945455168
5805050629165603
24375661619556703
36105231950324439
45342443221065693
18169686485050308
12956499749658231

result:

ok 

Test #4:

score: 10
Accepted
time: 110ms
memory: 20644kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 1 2 3 4 5 6 7 8 9 9 10 12 13 14 14 13 17 15 19 20 21 21 22 22 25 26 27 27 29 30 30 32 32 34 35 36 37 36 38 40 41 42 43 44 38 36 40 48 49 49 51 52 53 53 52 56 57 55 57 59 61 62 63 64 65 66 63 68 69 69 71 67 73 73 74 76 77 76 76 80 80 82 83 80 75 86 77 88 89 9...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
7643905133299046
28184208216232992
397398112600514
439994136720137
32751552084610538
34770551047442984
2746924426773012
1660650876324804
36635310270169815
52687563609961576

result:

ok 

Test #5:

score: 10
Accepted
time: 93ms
memory: 20308kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 1 2 3 4 5 6 7 8 9 8 11 12 13 13 12 14 15 18 19 20 21 22 23 24 23 26 27 28 29 30 30 32 31 34 35 36 35 37 37 40 41 42 43 43 45 43 47 48 47 50 51 50 48 54 55 55 57 58 59 59 61 62 61 60 62 52 67 68 69 70 70 72 73 74 71 74 75 78 78 78 78 58 83 46 61 86 73 88 89 8...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
26872827042939935
49372923666359196
9058883871784635
6777056622183544
1838319902044609
32141218683607317
3983594684931644
57790759896735111
27089846953780734
10261160977025592

result:

ok 

Test #6:

score: 10
Accepted
time: 89ms
memory: 20700kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 1 2 3 4 5 6 7 8 8 10 11 11 13 14 15 16 17 18 18 20 21 22 22 24 17 23 21 22 29 29 31 32 33 34 31 33 35 38 38 40 41 42 39 44 45 46 46 48 49 38 51 43 53 53 50 56 45 58 58 60 59 60 63 63 64 66 66 68 65 67 71 66 66 72 75 75 77 78 77 80 76 79 83 83 80 86 87 88 89 ...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
46240945687
75809785349
1427956109
18769152814
10917853217
38913156840
15656876405
40210377091
62339284486
12811886908

result:

ok 

Test #7:

score: 10
Accepted
time: 99ms
memory: 20688kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 1 2 3 3 4 6 7 8 9 10 10 12 13 14 11 16 17 18 19 20 21 21 23 24 25 25 27 24 28 30 31 32 28 34 35 36 37 22 29 23 17 31 43 43 45 46 43 48 49 47 51 51 53 46 49 56 57 58 58 60 61 62 57 64 63 66 65 45 69 70 71 72 68 23 75 76 77 73 79 80 81 82 83 84 84 85 87 88 89 ...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
40918849029853209
7833596601568197
5990593014536811
4352190437322498
17295263219976717
47008068426232620
954287740499985
15897745496652069
22735636717009101
8720508161191782

result:

ok 

Test #8:

score: 10
Accepted
time: 97ms
memory: 20376kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 1 2 3 4 4 6 7 8 8 9 11 12 7 14 15 15 17 16 17 17 21 22 23 17 20 14 25 28 26 30 30 32 33 31 35 36 33 38 35 40 41 41 30 38 45 31 33 48 49 50 51 33 50 53 55 56 56 58 59 60 59 62 63 64 56 66 66 68 62 60 55 62 59 74 74 76 77 77 32 80 81 82 44 58 85 85 85 88 89 89...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
18332177014668621
48287181796568495
21123963074015684
53693699485878843
2086270347806154
51638060827009153
25332123081029950
1389829310508093
14190661594976877
70996135211589918

result:

ok 

Test #9:

score: 10
Accepted
time: 95ms
memory: 19704kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 1 2 3 4 5 5 4 8 9 10 11 8 9 14 15 16 17 18 17 20 21 10 23 23 25 26 26 28 28 19 31 32 33 31 35 36 33 18 39 40 41 42 40 29 45 46 47 46 49 49 47 45 53 53 54 32 57 57 30 60 61 62 61 64 60 27 67 68 68 70 69 72 71 71 7 11 77 78 79 79 81 78 83 84 85 86 87 87 86 90 ...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
27482511519482973
54801483810360485
16427935358969097
18858137547390619
77884374862242783
26106356577065893
6900572582069509
10154611289838451
29452407535664386
51588785737271760

result:

ok 

Test #10:

score: 10
Accepted
time: 188ms
memory: 12788kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
76294866873700498
93890907422242820
93434331911152132
74666580729163472
52192075803472304
95086795576987856
59809293897104834
53869016712136914
77675882910684380
89712991728300302

result:

ok 

Subtask #2:

score: 0
Wrong Answer

Test #11:

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

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
160438450593
577688042235
744006666982
36207811594
945107130612
557597187959
150094946505
29573371752
117247975146
244421004974

result:

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

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Time Limit Exceeded

Test #33:

score: 0
Time Limit Exceeded

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:


result:


Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Time Limit Exceeded

Test #47:

score: 0
Time Limit Exceeded

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:


result:


Subtask #7:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%