QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#484888#6335. Belt ConveyorUnforgettablepl100 ✓467ms36488kbC++203.1kb2024-07-20 04:43:292024-07-20 04:43:29

Judging History

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

  • [2024-07-20 04:43:29]
  • 评测
  • 测评结果:100
  • 用时:467ms
  • 内存:36488kb
  • [2024-07-20 04:43:29]
  • 提交

answer

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

void Solve1(int N, vector<int> A, vector<int> B) {
	vector<vector<pair<int,int>>> adj(N);
	for(int i=0;i<N-1;i++){
		adj[A[i]].emplace_back(B[i],i);
		adj[B[i]].emplace_back(A[i],i);
	}
	vector<pair<int,int>> p(N);
	function<void(int,int)> dfs = [&](int x,int par){
		for(auto[v,i]:adj[x]){
			if(v==par)p[x]={v,i};
			else dfs(v,x);
		}
	};
	dfs(0,0);
	vector<int> ans(N-1);
	vector<bool> vis(N);
	vis[0]=true;
	for(int moves=0;moves<N-1;moves++){
		for(int v=0;v<N;v++){
			if(vis[v])continue;
			vector<int> directions(N-1),products(N);
			products[v]=1;
			for(auto[child,idx]:adj[v]){
				if(child==p[v].first)continue;
				if(!vis[child])continue;
				if(A[idx]==v and ans[idx]==0)directions[idx]=1;
				if(B[idx]==v and ans[idx]==1)directions[idx]=1;
			}
			auto t = Query(directions,products);
			if(t[v]){
				vis[v]=true;
				int idx = p[v].second;
				if(A[idx]==v)ans[idx]=1;
			} else if(t[p[v].first]){
				vis[v]=true;
				int idx = p[v].second;
				if(B[idx]==v)ans[idx]=1;
			} else {
				for(int impacted=0;impacted<N;impacted++){
					if(t[impacted]==0)continue;
					int idx = p[impacted].second;
					vis[impacted]=true;
					if(A[idx]==impacted)ans[idx]=1;
				}
			}
		}
	}
	Answer(ans);
}


void Solve(int N, vector<int> A, vector<int> B) {
	if(N<=30){
		Solve1(N,A,B);
		return;
	}
	vector<vector<pair<int,int>>> adj(N);
	for(int i=0;i<N-1;i++){
		adj[A[i]].emplace_back(B[i],i);
		adj[B[i]].emplace_back(A[i],i);
	}
	vector<pair<int,int>> p(N);
	vector<int> depth(N);
	vector<pair<int,int>> nodes = {{0,0},{0,1},{0,2}};
	function<void(int,int,int)> dfs = [&](int x,int par,int dep){
		depth[x] = dep;
		nodes[dep%3].first++;
		for(auto[v,i]:adj[x]){
			if(v==par)p[x]={v,i};
			else dfs(v,x,dep+1);
		}
	};
	dfs(0,0,0);
	vector<int> ans(N-1);
	vector<bool> vis(N);
	vis[0]=true;
	nodes[0].first--;
	for(int moves=0;moves<30;moves++){
		int offset = max_element(nodes.begin(),nodes.end())->second;
		vector<int> buffer;
		for(int i=0;i<N;i++)if(!vis[i] and depth[i]%3==offset)buffer.emplace_back(i);
		vector<int> directions(N-1),products(N);
		for(int&v:buffer){
			products[v]=1;
			for(auto[child,idx]:adj[v]){
				if(child==p[v].first)continue;
				if(!vis[child])continue;
				if(A[idx]==v and ans[idx]==0)directions[idx]=1;
				if(B[idx]==v and ans[idx]==1)directions[idx]=1;
			}
		}
		auto t = Query(directions,products);
		for(int&v:buffer){
			bool done = false;
			if(t[v]){
				vis[v]=true;
				nodes[depth[v]%3].first--;
				int idx = p[v].second;
				if(A[idx]==v)ans[idx]=1;
				done = true;
			} 
			if(!done){
				for(auto[impacted,i]:adj[v]){
					if(impacted==p[v].first)continue;
					if(t[impacted]==0)continue;
					int idx = p[impacted].second;
					vis[impacted]=true;
					nodes[depth[impacted]%3].first--;
					if(A[idx]==impacted)ans[idx]=1;
					done=true;
				}
			} 
			if(!done){
				vis[v]=true;
				int idx = p[v].second;
				nodes[depth[v]%3].first--;
				if(B[idx]==v)ans[idx]=1;
			} 
		}
	}
	Answer(ans);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 1
Accepted

Test #1:

score: 1
Accepted
time: 0ms
memory: 4136kb

input:

random1
2
0
1
1
0xC321A02965AC2640

output:

Accepted: 1

result:

ok correct

Test #2:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

random1
2
1
0
0
0x8A99AD9552B2C218

output:

Accepted: 1

result:

ok correct

Test #3:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

random1
2
1
0
1
0x024D21FA307D148D

output:

Accepted: 1

result:

ok correct

Test #4:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

random1
2
0
1
0
0x3C96AB23CEB63F75

output:

Accepted: 1

result:

ok correct

Subtask #2:

score: 14
Accepted

Dependency #1:

100%
Accepted

Test #5:

score: 14
Accepted
time: 0ms
memory: 4144kb

input:

priority
30
10 29 10 13 17 11 2 15 15 27 9 26 18 0 14 1 22 24 29 28 6 22 4 20 15 5 28 4 21
24 3 13 1 8 13 12 8 19 16 3 1 10 24 29 12 8 4 7 2 7 28 25 12 7 2 23 27 22
89058848 6377689 24189123 31671827 205117644 254374430 56016068 6819602 212866321 246625321 274047319 230485311 202854776 280075001 203...

output:

Accepted: 29

result:

ok correct

Test #6:

score: 0
Accepted
time: 0ms
memory: 3860kb

input:

random1
30
18 20 12 0 13 2 9 11 24 7 15 26 17 19 23 10 20 16 3 11 24 1 18 19 1 28 22 6 6
26 21 5 27 27 14 15 8 0 17 5 16 3 10 29 13 14 25 28 25 23 8 9 4 2 4 12 7 22
1 0 0 0 1 0 0 1 0 0 0 1 0 1 0 1 1 0 1 1 0 0 0 1 1 1 1 0 1
0x139BEEDAC0AE4AFB

output:

Accepted: 29

result:

ok correct

Test #7:

score: 0
Accepted
time: 0ms
memory: 3904kb

input:

priority
30
15 20 29 0 10 9 28 26 23 6 19 20 8 13 27 27 1 7 16 26 10 4 16 1 18 8 5 14 13
9 22 15 24 29 2 3 19 2 3 17 0 7 14 12 5 6 25 18 25 24 11 4 12 23 11 17 21 28
155983625 867841392 695948077 619352269 127722564 849426565 618649370 326405673 698896139 727112455 131828530 787535071 635627968 4725...

output:

Accepted: 29

result:

ok correct

Test #8:

score: 0
Accepted
time: 0ms
memory: 3908kb

input:

random1
30
11 11 11 11 23 20 11 11 11 26 11 21 11 11 11 27 11 11 11 16 13 17 5 11 11 1 11 14 11
24 28 10 3 11 11 22 25 8 11 29 11 12 15 9 11 19 0 2 11 11 11 11 18 4 11 7 11 6
0 1 1 0 0 1 1 1 0 1 1 0 0 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 1
0xD66348F4E914D783

output:

Accepted: 29

result:

ok correct

Test #9:

score: 0
Accepted
time: 0ms
memory: 4108kb

input:

priority
30
1 7 19 19 21 3 16 25 19 2 4 19 19 22 19 19 27 18 19 24 19 19 19 19 19 19 19 19 28
19 19 29 0 19 19 19 19 15 19 19 10 5 19 6 14 19 19 23 19 8 11 9 26 17 12 13 20 19
175687064 613757478 145110402 817656856 712251185 850089290 510909115 900701092 956086121 136191567 90104148 72809899 345506...

output:

Accepted: 29

result:

ok correct

Test #10:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

priority
30
22 22 22 16 13 1 13 22 15 6 21 22 2 23 27 22 4 13 3 13 26 5 13 22 9 8 11 25 13
0 14 13 13 29 13 7 18 22 22 13 28 22 13 22 12 22 20 22 24 13 13 10 17 13 22 22 13 19
205508605 212446816 92507839 281454564 232828716 252753556 236784221 262865505 235145960 298570090 277536286 225110287 21565...

output:

Accepted: 29

result:

ok correct

Subtask #3:

score: 10
Accepted

Test #11:

score: 10
Accepted
time: 250ms
memory: 35548kb

input:

random1
100000
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 9...

output:

Accepted: 30

result:

ok correct

Test #12:

score: 0
Accepted
time: 275ms
memory: 35664kb

input:

priority
100000
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 ...

output:

Accepted: 30

result:

ok correct

Test #13:

score: 0
Accepted
time: 219ms
memory: 36488kb

input:

random1
100000
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 9...

output:

Accepted: 30

result:

ok correct

Test #14:

score: 0
Accepted
time: 271ms
memory: 35680kb

input:

priority
100000
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 ...

output:

Accepted: 30

result:

ok correct

Subtask #4:

score: 75
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #15:

score: 75
Accepted
time: 420ms
memory: 24896kb

input:

random1
100000
80421 79656 7373 22779 46143 23525 47891 79913 37297 20998 75128 48153 63344 14542 7176 46311 14404 86722 64420 35721 9418 16518 68787 60231 62713 24600 3621 36142 16253 35726 59248 8570 29713 29710 65003 65386 98313 32539 48464 79006 7464 99396 45447 11929 44648 44081 94041 40159 307...

output:

Accepted: 30

result:

ok correct

Test #16:

score: 0
Accepted
time: 402ms
memory: 24964kb

input:

random1
100000
47543 22001 16105 85619 83739 65453 81631 39199 45451 20382 85595 14410 39199 30963 55201 76378 25120 7516 39199 54202 40278 55022 44298 24421 18026 66509 33880 81569 24498 99677 49879 5902 76830 19128 34499 73731 32890 52171 54572 39199 91782 49370 45817 61462 23515 15408 40298 74640...

output:

Accepted: 30

result:

ok correct

Test #17:

score: 0
Accepted
time: 416ms
memory: 25520kb

input:

random1
100000
54154 40864 51853 60873 46781 94584 40170 53625 38806 77573 2040 39786 34858 81565 80712 35628 88600 17657 29042 78470 12465 42107 99871 96640 83887 26160 67221 77210 16548 76907 36070 44287 83854 17095 84838 80345 84838 81932 77302 34933 63457 76048 85028 48884 95405 88687 84838 3426...

output:

Accepted: 30

result:

ok correct

Test #18:

score: 0
Accepted
time: 400ms
memory: 25028kb

input:

random1
100000
46303 33536 68847 90526 86976 41157 92976 55277 95773 61228 97873 17248 83140 45767 29523 34039 86976 87777 10360 74411 59948 86976 36897 96274 84266 22272 96274 96418 59791 38698 43246 7985 40195 99464 50308 47573 52887 79400 10704 67939 43632 18945 87838 87264 79027 20493 65917 8697...

output:

Accepted: 30

result:

ok correct

Test #19:

score: 0
Accepted
time: 397ms
memory: 24016kb

input:

random1
100000
83611 17213 87562 59306 20020 51610 30839 25762 52114 42830 75713 2390 28217 97024 7915 27090 860 42410 62147 79947 49279 57158 67068 28551 40726 37442 70900 695 38668 92005 24316 63893 61476 18296 31324 2908 81500 37570 90151 93028 17697 90387 89885 75850 10342 18198 33467 89357 3699...

output:

Accepted: 30

result:

ok correct

Test #20:

score: 0
Accepted
time: 441ms
memory: 25056kb

input:

priority
100000
34668 55115 28428 4188 5224 57930 19720 34748 80374 24826 73407 18811 40398 55419 34425 49986 7091 28878 39639 3279 34169 44061 15708 76855 64905 76437 28776 75973 85318 20756 27826 75213 76884 741 73071 76150 96103 99190 10598 36246 59779 85624 75485 48003 32691 32900 44660 9131 370...

output:

Accepted: 30

result:

ok correct

Test #21:

score: 0
Accepted
time: 467ms
memory: 30112kb

input:

priority
100000
8272 58707 53325 33503 38691 8924 23902 10906 10997 96511 35433 36047 75288 5749 82275 55585 59320 19906 16161 51013 24088 3579 52846 80048 79350 77323 45373 11964 60563 32793 15132 89763 7376 26995 66940 69425 47193 17718 76475 67083 2881 42816 87861 80109 80894 30605 93227 36302 46...

output:

Accepted: 30

result:

ok correct

Test #22:

score: 0
Accepted
time: 354ms
memory: 26808kb

input:

priority
100000
10075 75068 42757 34929 5635 88324 14086 51168 29480 62829 22115 12664 34168 98871 97836 72076 42854 54927 58402 74534 5452 3764 46213 32512 91857 92312 43954 73818 41339 73818 24613 14049 55850 89744 44216 25404 35269 76598 81358 38214 56590 82025 73170 9783 48027 88758 14989 9892 5...

output:

Accepted: 30

result:

ok correct

Test #23:

score: 0
Accepted
time: 428ms
memory: 25136kb

input:

random1
100000
39886 43410 20620 76609 96282 4043 56966 38057 73158 96987 12512 52010 33559 37491 1756 50948 92125 55018 10094 61672 32994 14874 78788 68719 67017 45806 9548 79250 53931 15675 37993 93904 27315 85393 57194 51994 38595 38711 73045 70584 64968 72140 47569 4611 60822 45041 83550 74372 6...

output:

Accepted: 30

result:

ok correct

Test #24:

score: 0
Accepted
time: 442ms
memory: 24844kb

input:

priority
100000
77439 97917 89577 30523 22128 31511 44115 73995 32792 19689 3191 29387 85085 44651 16199 36643 76887 48848 46369 81191 97923 75269 61624 22472 86302 21442 44348 57983 69707 49496 73500 59444 62166 91226 26551 60132 17895 55097 87236 21104 92475 46348 22835 77540 3426 90137 10106 3163...

output:

Accepted: 30

result:

ok correct

Test #25:

score: 0
Accepted
time: 420ms
memory: 24316kb

input:

random1
100000
90056 23481 54991 48747 10869 47171 28644 20929 20508 73186 22594 8629 34162 68826 34638 22030 38313 10262 94043 50634 91602 24716 11039 46202 46636 12297 27686 81910 87812 77670 53585 61515 64012 24724 37439 58388 41191 42491 64679 9997 54580 63520 85314 17969 79293 90747 747 63267 7...

output:

Accepted: 30

result:

ok correct

Test #26:

score: 0
Accepted
time: 438ms
memory: 24336kb

input:

priority
100000
82983 53806 58721 49562 46682 2205 64805 49213 32078 11101 90854 73323 28047 3391 73634 20005 38351 30472 2735 67042 33968 81977 18390 34268 52700 77158 59135 76206 51619 71525 36184 24003 7570 57660 15904 42348 38319 72567 70668 61496 23725 8465 99563 69558 17813 58605 66206 90221 3...

output:

Accepted: 30

result:

ok correct

Test #27:

score: 0
Accepted
time: 434ms
memory: 24340kb

input:

priority
100000
23687 72079 84228 5605 43655 23367 86248 30399 85734 13059 96277 31021 28262 94026 784 43550 31733 63840 5044 38346 31111 34745 44054 56928 77101 67424 70437 91204 10371 9335 51851 35025 22270 77070 46995 92655 5539 76526 94191 89673 46321 94461 90070 66428 77614 30022 20664 11834 20...

output:

Accepted: 30

result:

ok correct

Test #28:

score: 0
Accepted
time: 290ms
memory: 26432kb

input:

random1
100000
75293 75293 45013 47419 50486 75293 97976 75293 31253 2388 32384 75293 75293 75293 82899 75293 46145 75293 88247 80203 61006 91769 39236 75293 75293 64380 82730 75293 79899 16818 64062 49362 75293 75293 32066 92355 81071 5065 75293 28857 82373 92604 16331 75293 75293 79642 23246 75293...

output:

Accepted: 30

result:

ok correct

Test #29:

score: 0
Accepted
time: 369ms
memory: 26424kb

input:

priority
100000
79116 79116 14206 79116 79116 80061 79116 62865 56658 75639 41553 56345 79116 33387 79116 52459 79116 79116 13441 79116 19550 52507 79116 79116 87258 9823 79116 79116 31996 66513 79116 12063 79116 49008 79116 90513 79116 79116 79116 79116 79116 79116 79116 79116 79116 7196 27641 3639...

output:

Accepted: 30

result:

ok correct

Test #30:

score: 0
Accepted
time: 385ms
memory: 25132kb

input:

priority
100000
44306 51652 42855 75382 80249 44306 44306 44306 31081 57343 44306 19931 51652 60560 31830 33369 44306 64444 51652 45394 55433 51652 51652 99164 63176 51652 41944 44306 67152 44306 44306 44306 27574 81557 44306 8308 82963 44306 51652 51652 11776 83746 51652 44306 51652 9979 23480 4984...

output:

Accepted: 30

result:

ok correct