QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#875586#2745. Mechanical DollAlimkhan12 749ms164956kbC++231.8kb2025-01-29 23:33:262025-01-29 23:33:27

Judging History

This is the latest submission verdict.

  • [2025-01-29 23:33:27]
  • Judged
  • Verdict: 12
  • Time: 749ms
  • Memory: 164956kb
  • [2025-01-29 23:33:26]
  • Submitted

answer

#include "doll.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ff first
#define ss second

const int maxn = 1e6 + 10;

int n, m, s, pw, l, id, a[maxn], cnt;
vector <int> X, Y;
vector <int> c;
vector <int> A1;
map <int, int> lf, rg, used;
vector <pair <int, int> > d;

inline void get(int v, int tl, int tr) {
	int tm = (tl + tr) / 2;
	if (tm <= l) {
		lf[v] = -1;
	}
	if (tm + 1 == tr) {
		rg[v] = a[tr];
		// cnt++;
	} else {
		s--;
		rg[v] = s;
		get(s, tm + 1, tr);
	}
	if (tl == tm && lf[v] == 0) {
		lf[v] = a[tl];
		// cnt++;
	} else {
		if (lf[v] == 0) {
			s--;
			lf[v] = s;
			get(s, tl, tm);
		}
	}
	// cout << v << " " << lf[v] << " " << rg[v] << '\n';
}

inline void dfs(int v) {
	used[v]++;
	if (v == 0) return;
	if (cnt >= A1.size()) return;
	if (used[v] % 2 == 1) {
		if (lf[v] == m + 1) {
			lf[v] = A1[cnt];
			cnt++;
			if (lf[v] == 0) return;
			dfs(-1);
		} else {
			dfs(lf[v]);
		}
	} else {
		if (rg[v] == m + 1) {
			rg[v] = A1[cnt];
			cnt++;
			if (rg[v] == 0) return;
			dfs(-1);
		
		} else {
			dfs(rg[v]);
		}
	}
}

void create_circuit(int M, std::vector<int> A) {
	A.push_back(0);	
	c = {A[0]};
	A.erase(A.begin());
	// a = A;
	A1 = A;
	n = A.size();
	m = M;
	pw = 2;
	while(pw < n) {
		pw *= 2;
	}
	fill(a + 1, a + pw + 1, m + 1);
	while(l + n < pw) {
		l++;
		a[l] = -1;
	}
	s = -1;
	get(-1, 1, pw);
	dfs(-1);
	for (int i = 1; i <= M; i++) {
		c.push_back(-1);
	}
	// c.push_back(-1);
	for (int i = -1; i >= s; i--) {
		X.push_back(lf[i]);
		Y.push_back(rg[i]);
		// cout << i << " " << lf[i] << " " << rg[i] << '\n';
	}
	// for (int i = 0; i < c.size(); i++) {
	// 	cout << c[i] << " ";
	// }
	// cout << '\n';
	answer(c, X, Y);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 2
Accepted

Test #1:

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

input:

9 9
2 9 8 1 3 7 6 4 5

output:

Accepted: 11 54

result:

points 1

Test #2:

score: 2
Accepted
time: 453ms
memory: 98388kb

input:

100000 65536
13224 49549 24094 37805 90252 12892 7340 44487 93869 65919 83328 38749 45169 86649 56693 3303 75024 87778 80950 3269 79176 61578 35845 51581 96551 67857 13907 97387 75768 45565 89490 5018 103 41086 67064 9397 48489 68440 92764 32166 96653 66672 56950 86902 56409 70305 63374 77757 17781 ...

output:

Accepted: 65535 1048576

result:

points 1

Test #3:

score: 2
Accepted
time: 471ms
memory: 119000kb

input:

65537 65537
6441 24592 10760 39557 65462 30956 18436 9519 362 26018 25701 48274 47132 23414 12942 24379 58211 44126 23389 32686 48760 13253 65374 33337 12554 35737 16084 39919 42895 33833 19274 2894 18348 360 23026 58809 17915 58960 25582 45951 19578 25984 17149 34944 20240 62018 17167 52414 47657 4...

output:

Accepted: 65552 1310718

result:

points 1

Test #4:

score: 2
Accepted
time: 749ms
memory: 164956kb

input:

100000 100000
83254 62169 5236 21438 78363 14751 44638 2177 98268 60571 99414 18022 36403 50495 98037 57665 15840 74546 77473 70363 89184 46970 79155 39699 98519 49754 30108 58902 71395 16757 66405 96614 85750 35994 80062 68050 62099 60537 37156 54644 20810 62140 95068 7580 56792 86118 40233 6526 37...

output:

Accepted: 100006 1818080

result:

points 1

Test #5:

score: 2
Accepted
time: 1ms
memory: 3840kb

input:

16 16
10 9 12 15 3 2 8 14 1 5 6 4 13 11 7 16

output:

Accepted: 15 64

result:

points 1

Test #6:

score: 2
Accepted
time: 0ms
memory: 4820kb

input:

100000 16
44135 56348 19047 45933 82429 97231 20613 10472 34398 72594 60486 14499 13048 53662 38600 74603

output:

Accepted: 15 64

result:

points 1

Test #7:

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

input:

1 1
1

output:

Accepted: 1 2

result:

points 1

Subtask #2:

score: 0
Time Limit Exceeded

Test #8:

score: 0
Time Limit Exceeded

input:

65537 131072
38169 29889 63383 43430 55643 44435 63973 61457 18223 38917 62266 26543 10814 970 44978 20275 62383 23625 55275 37609 18805 62029 32115 42887 25636 51086 64204 11787 41137 16164 3764 59071 41518 13112 48670 57859 63154 43506 4175 38360 56815 16082 35241 41583 11729 45167 16539 36608 524...

output:

Accepted: 131071 2228224

result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #14:

score: 0
Time Limit Exceeded

input:

66666 199998
46730 34215 30702 41294 43268 29126 13518 38942 42908 58361 10352 13453 61990 51635 45179 17080 11893 59293 8765 48892 9847 29159 4183 35752 44930 54866 19016 8489 9471 61999 29220 3802 39755 15070 38640 20910 16621 20205 2930 36405 53436 33759 40537 24283 20254 60792 29716 4450 42478 2...

output:

Unauthorized output

result:


Subtask #4:

score: 10
Accepted

Test #23:

score: 10
Accepted
time: 1ms
memory: 3968kb

input:

5 16
2 4 2 4 5 5 2 4 5 4 2 2 5 5 4 1

output:

Accepted: 15 64

result:

points 1

Test #24:

score: 10
Accepted
time: 0ms
memory: 3968kb

input:

3 16
2 3 3 2 2 1 2 1 2 2 1 1 3 3 3 1

output:

Accepted: 15 64

result:

points 1

Test #25:

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

input:

3 16
3 3 3 3 1 1 3 3 3 2 3 3 2 1 1 1

output:

Accepted: 15 64

result:

points 1

Test #26:

score: 10
Accepted
time: 1ms
memory: 3840kb

input:

2 16
1 2 2 1 2 1 2 2 1 2 2 1 2 1 1 2

output:

Accepted: 15 64

result:

points 1

Test #27:

score: 10
Accepted
time: 0ms
memory: 3968kb

input:

2 16
1 1 2 2 1 2 2 2 2 1 2 2 2 2 2 1

output:

Accepted: 15 64

result:

points 1

Test #28:

score: 10
Accepted
time: 1ms
memory: 3840kb

input:

1 16
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

output:

Accepted: 15 64

result:

points 1

Test #29:

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

input:

4 16
2 3 1 2 2 4 1 1 3 3 1 3 3 4 1 4

output:

Accepted: 15 64

result:

points 1

Test #30:

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

input:

4 16
4 2 3 2 2 2 2 1 3 1 2 3 4 2 1 3

output:

Accepted: 15 64

result:

points 1

Subtask #5:

score: 0
Time Limit Exceeded

Test #31:

score: 18
Accepted
time: 1ms
memory: 3840kb

input:

1 33
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

output:

Accepted: 37 286

result:

points 1

Test #32:

score: 0
Time Limit Exceeded

input:

1 131072
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

Accepted: 131071 2228224

result:


Subtask #6:

score: 0
Time Limit Exceeded

Test #35:

score: 0
Time Limit Exceeded

input:

40000 200000
18605 24497 29838 20963 4861 7592 1633 39477 36565 8297 18190 30474 13552 13537 21338 11904 20265 31867 16132 3720 10773 14695 7860 2766 29 34536 36990 22269 35364 15921 24814 6064 39832 24011 17689 20704 9159 7612 1993 36334 29110 2976 29779 10914 25954 17922 39388 28558 30311 7769 195...

output:

Unauthorized output

result: