QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#851426#8320. 种树sherman2022100 ✓692ms27716kbC++142.6kb2025-01-10 18:54:292025-01-10 18:54:30

Judging History

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

  • [2025-01-10 18:54:30]
  • 评测
  • 测评结果:100
  • 用时:692ms
  • 内存:27716kb
  • [2025-01-10 18:54:29]
  • 提交

answer

#include <bits/stdc++.h>

#define eb emplace_back
#define ulll unsigned __int128

using namespace std;

const int N = 140 + 5;

vector<int> G[N]; 
ulll t, g, ca[N];
int pp[N];

int tot = 0;
void DFS1(int u) {
	if(u != 1) pp[++ tot] = 1;
	for(int v : G[u]) DFS1(v);
	if(u != 1) pp[++ tot] = 0;
}

void Write1(ulll x) {
	if(x >= 10) Write1(x / 10);
	cerr << (char)(x % 10 + '0');
}

ulll Get(int l, int r) {
	if(l + 1 == r) return 1;
	if(l > r) return 1;
	int cnt = 1, k;
	for(int i = l + 1; i <= r; ++ i) {
		cnt += pp[i] == 1 ? 1 : -1;
		if(cnt == 0) {
			k = i;
			break;
		}
	}
	ulll t = 0;
	for(int j = 1; j < (k - l + 1) / 2; ++ j) t += (ulll)ca[j - 1] * ca[(r - l + 1) / 2 - j];
	ulll t1 = Get(l + 1, k - 1), t2 = Get(k + 1, r);
//	Write1(t + (t1 - 1) * ca[(r - k) / 2] + t2), cerr << "\n" << endl;
	return t + (t1 - 1) * ca[(r - k) / 2] + t2;
}

ulll encoder(int n, const int *p) {
	ca[0] = 1, ca[1] = 1, ca[2] = 2;
	for(int i = 3; i < n; ++ i) {
		if(ca[i - 1] % (i + 1) == 0) ca[i] = ca[i - 1] / (ulll)(i + 1) * (ulll)(4 * i - 2);
		else ca[i] = ca[i - 1] * (ulll)(4 * i - 2) / (ulll)(i + 1);
//		Write1(ca[i]), cerr << endl;
	}
//	Write1(ca[70]), cerr << endl;
	for(int i = 1; i <= n; ++ i) G[i].clear();
	for(int i = 2; i <= n; ++ i) G[p[i]].eb(i);
	for(int i = 1; i <= n; ++ i) sort(G[i].begin(), G[i].end());
	tot = 0, DFS1(1);
	return Get(1, tot);
}

int st[N], tp;
int gh[N];

void Solve(int l, int r, ulll x) {
	if(l == r - 1) {
		gh[l] = 1, gh[r] = 0;
		return ;
	}
	if(l > r) return ;
	for(int j = 1; j <= (r - l + 1) / 2; ++ j) {
		if(x > ca[j - 1] * ca[(r - l + 1) / 2 - j]) x -= ca[j - 1] * ca[(r - l + 1) / 2 - j];
		else {
			gh[l] = 1, gh[l + 2 * j - 1] = 0;
			ulll t1, t2;
			if(x % ca[(r - l + 1) / 2 - j] == 0) t2 = ca[(r - l + 1) / 2 - j], t1 = x / ca[(r - l + 1) / 2 - j];
			else t2 = x % ca[(r - l + 1) / 2 - j], t1 = x / ca[(r - l + 1) / 2 - j] + 1;
			Solve(l + 1, l + 2 * j - 2, t1);
			Solve(l + 2 * j, r, t2);
			return ;
		}
	}
}

void Write(ulll x) {
	if(x >= 10) Write(x / 10);
	cerr << (char)(x % 10 + '0');
}

void decoder(int n, unsigned __int128 M, int *p) {
	ca[0] = 1, ca[1] = 1, ca[2] = 2;
	for(int i = 3; i < n; ++ i) {
		if(ca[i - 1] % (i + 1) == 0) ca[i] = ca[i - 1] / (ulll)(i + 1) * (ulll)(4 * i - 2);
		else ca[i] = ca[i - 1] * (ulll)(4 * i - 2) / (ulll)(i + 1);
	}
	for(int i = 1; i <= 2 * n - 2; ++ i) gh[i] = 0;
	Solve(1, 2 * n - 2, M);
	st[++ tp] = 1;
	for(int i = 1, j = 2; i <= 2 * (n - 1); ++ i) {
		if(gh[i]) p[j] = st[tp], st[++ tp] = j ++;
		else tp --;
	}
	tp = 0;
	return ;
}

詳細信息

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 18ms
memory: 4324kb

Manager to Encoder

3000
64
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 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 36 14 30 9 50 27 42 13 18 34 16 12 22 47 
94295396480570588193565136480873139
65
0 1 2 2 2 3 1 7 1 8 6 10 8 6 5 1 15 1 6 18 2 6 12 10 14 13 10 9 20 29 1...

Encoder to Manager

3000
64
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 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 36 14 30 9 50 27 42 13 18 34 16 12 22 47 
94295396480570588193565136480873139
65
0 1 2 2 2 3 1 7 1 8 6 10 8 6 5 1 15 1 6 18 2 6 12 10 14 13 10 9 20 29 1...

Manager to Decoder

3000
64
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 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 36 14 30 9 50 27 42 13 18 34 16 12 22 47 
94295396480570588193565136480873139
65
0 1 2 2 2 3 1 7 1 8 6 10 8 6 5 1 15 1 6 18 2 6 12 10 14 13 10 9 20 29 1...

Decoder to Manager

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 24 24 27 24 24 24 31 24 24 24 24 36 24 24 39 24 24 24 24 24 24 46 24 24 24 24 24 52 24 24 24 56 22 18 16 14 13 12 9 
0 1 2 3 4 4 6 4 8 9 10 11 11 10 10 15 9 8 4 19 4 4 2 2 24 25 26 27 27 24 30 2 2 1 34 35 36 37 38 36 36 35 42 35 1 45 4...

result:

ok Right output.

Subtask #2:

score: 15
Accepted

Test #2:

score: 15
Accepted
time: 19ms
memory: 4632kb

Manager to Encoder

3000
66
0 1 1 2 4 2 6 7 3 3 6 9 10 10 13 4 8 12 15 5 18 15 9 13 8 5 17 20 17 16 11 19 18 30 29 22 23 35 37 33 36 27 27 7 23 25 21 46 22 45 40 25 20 43 38 41 34 35 34 29 50 42 47 24 24 40 
723178141248849160013052545237377013
70
0 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 ...

Encoder to Manager

3000
66
0 1 1 2 4 2 6 7 3 3 6 9 10 10 13 4 8 12 15 5 18 15 9 13 8 5 17 20 17 16 11 19 18 30 29 22 23 35 37 33 36 27 27 7 23 25 21 46 22 45 40 25 20 43 38 41 34 35 34 29 50 42 47 24 24 40 
723178141248849160013052545237377013
70
0 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 ...

Manager to Decoder

3000
66
0 1 1 2 4 2 6 7 3 3 6 9 10 10 13 4 8 12 15 5 18 15 9 13 8 5 17 20 17 16 11 19 18 30 29 22 23 35 37 33 36 27 27 7 23 25 21 46 22 45 40 25 20 43 38 41 34 35 34 29 50 42 47 24 24 40 
723178141248849160013052545237377013
70
0 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 ...

Decoder to Manager

0 1 2 3 4 5 5 4 3 9 10 11 11 2 14 15 16 17 18 19 18 21 17 23 24 25 24 23 16 29 30 29 15 14 34 1 36 37 38 39 40 41 39 43 44 44 37 47 48 47 50 51 36 53 54 55 56 55 58 59 60 58 54 63 63 53 
0 1 1 1 4 1 1 1 1 9 1 11 12 1 1 1 1 17 18 19 17 21 1 23 23 1 26 1 1 1 1 31 32 31 1 35 1 1 38 39 1 1 42 1 44 45 1 ...

result:

ok Right output.

Subtask #3:

score: 15
Accepted

Test #3:

score: 15
Accepted
time: 559ms
memory: 26884kb

Manager to Encoder

100000
70
0 1 2 2 2 2 1 2 4 8 3 1 6 12 13 6 1 14 2 8 3 6 2 1 8 25 24 5 10 11 30 28 15 7 23 20 12 29 28 17 31 27 10 18 6 3 38 39 40 43 7 33 23 23 38 28 24 26 57 44 16 18 20 39 9 26 25 16 67 58 
180578025385120277877941711259748853180
67
0 1 1 1 1 4 3 4 6 2 10 3 10 7 14 6 11 15 7 13 6 14 18 9 9 4 20 2...

Encoder to Manager

100000
70
0 1 2 2 2 2 1 2 4 8 3 1 6 12 13 6 1 14 2 8 3 6 2 1 8 25 24 5 10 11 30 28 15 7 23 20 12 29 28 17 31 27 10 18 6 3 38 39 40 43 7 33 23 23 38 28 24 26 57 44 16 18 20 39 9 26 25 16 67 58 
180578025385120277877941711259748853180
67
0 1 1 1 1 4 3 4 6 2 10 3 10 7 14 6 11 15 7 13 6 14 18 9 9 4 20 2...

Manager to Decoder

100000
70
0 1 2 2 2 2 1 2 4 8 3 1 6 12 13 6 1 14 2 8 3 6 2 1 8 25 24 5 10 11 30 28 15 7 23 20 12 29 28 17 31 27 10 18 6 3 38 39 40 43 7 33 23 23 38 28 24 26 57 44 16 18 20 39 9 26 25 16 67 58 
180578025385120277877941711259748853180
67
0 1 1 1 1 4 3 4 6 2 10 3 10 7 14 6 11 15 7 13 6 14 18 9 9 4 20 2...

Decoder to Manager

0 1 2 3 4 5 6 3 3 2 10 11 2 13 14 14 16 16 14 2 20 21 22 23 20 25 25 20 20 2 30 31 32 33 33 31 36 30 38 38 30 41 42 43 42 41 46 2 2 49 49 49 1 53 53 1 56 57 58 59 58 56 1 63 64 1 66 67 66 69 
0 1 2 3 4 5 3 7 8 8 8 8 7 7 3 15 2 17 1 19 20 21 22 23 24 23 23 27 21 29 21 20 20 33 20 35 20 37 37 20 20 19...

result:

ok Right output.

Subtask #4:

score: 20
Accepted

Test #4:

score: 20
Accepted
time: 560ms
memory: 27716kb

Manager to Encoder

100000
68
0 1 1 3 4 4 3 5 7 8 8 10 9 10 11 11 14 15 7 14 13 6 17 6 21 16 20 25 9 2 5 28 25 24 30 32 27 16 23 33 27 26 42 22 15 40 2 22 31 12 47 50 18 12 38 50 39 18 52 34 38 59 56 61 19 46 55 56 
8447676714480522165231579637469133728
70
0 1 2 1 2 4 4 3 6 6 7 10 11 5 9 15 13 9 5 11 7 14 22 20 21 21 1...

Encoder to Manager

100000
68
0 1 1 3 4 4 3 5 7 8 8 10 9 10 11 11 14 15 7 14 13 6 17 6 21 16 20 25 9 2 5 28 25 24 30 32 27 16 23 33 27 26 42 22 15 40 2 22 31 12 47 50 18 12 38 50 39 18 52 34 38 59 56 61 19 46 55 56 
8447676714480522165231579637469133728
70
0 1 2 1 2 4 4 3 6 6 7 10 11 5 9 15 13 9 5 11 7 14 22 20 21 21 1...

Manager to Decoder

100000
68
0 1 1 3 4 4 3 5 7 8 8 10 9 10 11 11 14 15 7 14 13 6 17 6 21 16 20 25 9 2 5 28 25 24 30 32 27 16 23 33 27 26 42 22 15 40 2 22 31 12 47 50 18 12 38 50 39 18 52 34 38 59 56 61 19 46 55 56 
8447676714480522165231579637469133728
70
0 1 2 1 2 4 4 3 6 6 7 10 11 5 9 15 13 9 5 11 7 14 22 20 21 21 1...

Decoder to Manager

0 1 2 3 2 5 1 7 8 9 10 11 12 13 14 15 13 17 17 12 11 21 22 23 24 21 26 27 27 10 30 31 32 32 31 30 36 37 38 36 40 41 40 43 9 45 8 47 48 48 47 51 52 7 54 55 56 57 58 59 60 58 62 63 64 55 54 67 
0 1 2 3 4 3 2 7 8 9 10 11 8 13 14 15 13 17 18 7 20 21 21 23 20 1 26 27 28 29 30 31 30 29 28 35 35 27 38 39 4...

result:

ok Right output.

Subtask #5:

score: 30
Accepted

Test #5:

score: 30
Accepted
time: 692ms
memory: 25744kb

Manager to Encoder

100000
70
0 1 1 3 3 5 4 5 8 8 4 9 11 9 11 14 7 13 2 14 17 15 12 6 18 21 20 22 18 25 7 10 27 22 15 32 30 6 33 38 25 19 10 16 32 36 23 36 41 29 38 17 21 16 45 37 23 24 37 19 30 29 27 42 53 41 2 64 58 40 
137887995841540204383746989127288597932
65
0 1 2 3 3 4 2 5 5 6 10 10 8 1 13 5 6 4 4 5 5 15 16 16 6...

Encoder to Manager

100000
70
0 1 1 3 3 5 4 5 8 8 4 9 11 9 11 14 7 13 2 14 17 15 12 6 18 21 20 22 18 25 7 10 27 22 15 32 30 6 33 38 25 19 10 16 32 36 23 36 41 29 38 17 21 16 45 37 23 24 37 19 30 29 27 42 53 41 2 64 58 40 
137887995841540204383746989127288597932
65
0 1 2 3 3 4 2 5 5 6 10 10 8 1 13 5 6 4 4 5 5 15 16 16 6...

Manager to Decoder

100000
70
0 1 1 3 3 5 4 5 8 8 4 9 11 9 11 14 7 13 2 14 17 15 12 6 18 21 20 22 18 25 7 10 27 22 15 32 30 6 33 38 25 19 10 16 32 36 23 36 41 29 38 17 21 16 45 37 23 24 37 19 30 29 27 42 53 41 2 64 58 40 
137887995841540204383746989127288597932
65
0 1 2 3 3 4 2 5 5 6 10 10 8 1 13 5 6 4 4 5 5 15 16 16 6...

Decoder to Manager

0 1 2 3 4 5 3 2 1 9 10 11 12 13 13 15 12 11 10 19 20 21 22 23 24 24 23 22 28 28 21 31 31 19 34 35 35 34 9 39 40 41 42 40 44 45 44 39 48 49 50 51 51 49 54 55 55 54 58 59 60 59 48 63 64 65 65 64 68 63 
0 1 2 3 4 5 6 7 6 6 10 11 11 10 14 10 6 6 5 19 19 21 5 23 5 4 26 4 28 29 30 3 32 33 34 35 36 37 37 3...

result:

ok Right output.