QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#407819#4252. Permutationzhaohaikun#91.333333 166ms4036kbC++202.8kb2024-05-09 11:40:142024-05-09 11:40:15

Judging History

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

  • [2024-05-09 11:40:15]
  • 评测
  • 测评结果:91.333333
  • 用时:166ms
  • 内存:4036kb
  • [2024-05-09 11:40:14]
  • 提交

answer

#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#include "perm.h"
// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "\033[32m[" << __LINE__ << "]\033[0m "
#define SZ(x) ((int) x.size() - 1)
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T& chkmax(T& x, T y) {return x = max(x, y);}
template <typename T> T& chkmin(T& x, T y) {return x = min(x, y);}
template <typename T> T& read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x *= f;
}
mt19937 mrand(20070803);
const int T = 90;
inline int rnd(int l, int r) {return mrand() % (r - l + 1) + l;}
int cc(ll n) {
	if (n == 0) return 0;
	if (n % 2 == 1) return cc(n / 2) + 1;
	return cc(n - 1) + 1;
}
vector <int> solve(ll n) {
	if (n == 0) return vector <int> {};
	if (n % 2 == 1) {
		vector <int> ans = solve(n / 2);
		int t = ans.size();
		ans.push_back(t);
		return ans;
	}
	vector <int> ans = solve(n - 1);
	// int t = ans.size();
	for (int& i: ans) i++;
	ans.push_back(0);
	return ans;
}
// ll dp[1010];
ll t[1010];
int len;
void modify(int x, ll y) {
	for (; x <= len; x += x & -x) t[x] += y;
}
ll query(int x) {
	ll s = 0;
	for (; x; x ^= x & -x) s += t[x];
	return s;
}
ll calc(vector <int> x) {
	len = SZ(x);
	F(i, 1, len) t[i] = 0;
	ll s = 0;
	F(i, 0, SZ(x)) {
		ll w = 1 + query(x[i]);
		// F(j, 0, i - 1) {
		// 	if (x[j] < x[i]) {
		// 		dp[i] += dp[j];
		// 	}
		// }
		s += w;
		modify(x[i] + 1, w);
	}
	return s;
}
std::vector<int> construct_permutation(ll n) {
	n--;
	vector <int> ans;
	// if (n <= 90) {
	// 	F(i, 1, n) ans.push_back(n - i);
	// 	return ans;
	// }
	ans = solve(n);
	int lim = 1;
	F(i, 1, 7) {
		vector <int> t(i);
		F(j, 1, i) t[j - 1] = j - 1;
		// lim = min(500, lim * i);
		do {
		// F(j, 1, lim) {
			shuffle(all(t), mrand);
			ll v = calc(t);
			// debug << v << endl;
			if (n >= v) {
				// vector <int> w = cc(n - v);
				if (cc(n - v) + i < ans.size()) {
					vector <int> w = solve(n - v);
					ans.clear();
					for (int j: t) ans.push_back(j + w.size());
					for (int j: w) ans.push_back(j);
					if (ans.size() <= T) break;
				}
			}
		// }
		} while (next_permutation(all(t)));
		// if (ans.size() <= T) break;
	}
	return ans;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 52ms
memory: 3960kb

input:

a92b3f80-b312-8377-273c-3916024d7f2a
89
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

output:

6cad0f33-b1bd-3a3e-1a8d-c4af23adfcbf
OK
1
0
2
1 0
2
0 1
3
1 2 0
3
1 0 2
4
2 1 3 0
3
0 1 2
4
1 2 3 0
4
1 2 0 3
5
2 3 1 4 0
4
1 0 2 3
5
2 1 3 4 0
5
2 1 3 0 4
5
1 0 4 2 3
4
0 1 2 3
5
1 2 3 4 0
5
1 2 3 0 4
6
2 3 4 1 5 0
5
1 2 0 3 4
6
2 3 1 4 5 0
6
2 3 1 4 0 5
6
1 2 4 0 5 3
5
1 0 2 3 4
6
2 1 3 4 5 0
6
2 ...

result:

ok 

Subtask #2:

score: 81.3333
Acceptable Answer

Test #2:

score: 90
Accepted
time: 79ms
memory: 3992kb

input:

a92b3f80-b312-8377-273c-3916024d7f2a
100
39993
85709
48645
25391
15360
54084
28947
18808
86735
316
14357
82845
96210
16242
58466
43439
77462
70742
76176
20397
30314
22634
29622
81835
31904
81283
37072
36527
26764
55878
72762
5262
34915
63468
20595
66579
77373
36670
89340
83384
73268
31960
67318
3908...

output:

6cad0f33-b1bd-3a3e-1a8d-c4af23adfcbf
OK
22
7 8 9 6 10 5 11 4 12 13 14 15 16 3 17 2 18 1 19 20 21 0
25
9 10 8 11 12 13 7 14 6 15 5 16 17 4 18 3 19 20 21 2 22 1 23 24 0
22
7 8 6 9 5 10 4 11 3 12 2 13 14 15 16 17 18 19 1 20 21 0
22
8 7 9 10 11 12 6 13 5 14 15 16 4 17 18 3 19 2 20 1 21 0
16
3 2 4 1 5 0 ...

result:

ok 

Test #3:

score: 90
Accepted
time: 81ms
memory: 3996kb

input:

a92b3f80-b312-8377-273c-3916024d7f2a
100
2147483647
1073741823
536870911
268435455
134217727
67108863
33554431
16777215
8388607
4194303
2097151
1582
24319
38
463
7
1073741503
3
18
3
3780
2
24934
124910
65535
154
1069539071
209452285
1662
3
3
93
4070
131071
502986749
3164
268430159
247
21746
124927
1...

output:

6cad0f33-b1bd-3a3e-1a8d-c4af23adfcbf
OK
60
30 29 31 28 32 27 33 26 34 25 35 24 36 23 37 22 38 21 39 20 40 19 41 18 42 17 43 16 44 15 45 14 46 13 47 12 48 11 49 10 50 9 51 8 52 7 53 6 54 5 55 4 56 3 57 2 58 1 59 0
58
29 28 30 27 31 26 32 25 33 24 34 23 35 22 36 21 37 20 38 19 39 18 40 17 41 16 42 15 ...

result:

ok 

Test #4:

score: 81.3333
Acceptable Answer
time: 115ms
memory: 4000kb

input:

a92b3f80-b312-8377-273c-3916024d7f2a
100
576460752303423487
288230376151711743
144115188075855871
72057594037927935
36028797018963967
18014398509481983
9007199254740991
4503599627370495
2251799813685247
1125899906842623
562949953421311
8166608599550
16508780543
33554427
43000192155799
62353919
71773...

output:

6cad0f33-b1bd-3a3e-1a8d-c4af23adfcbf
OK
116
58 57 59 56 60 55 61 54 62 53 63 52 64 51 65 50 66 49 67 48 68 47 69 46 70 45 71 44 72 43 73 42 74 41 75 40 76 39 77 38 78 37 79 36 80 35 81 34 82 33 83 32 84 31 85 30 86 29 87 28 88 27 89 26 90 25 91 24 92 23 93 22 94 21 95 20 96 19 97 18 98 17 99 16 100 ...

result:

points 0.90370370370

Test #5:

score: 90
Accepted
time: 120ms
memory: 3828kb

input:

a92b3f80-b312-8377-273c-3916024d7f2a
100
336455856505
197522918480
260689715591
857530435844
89809708292
207893569808
702779448503
917149928374
643600357316
927175148543
51879726697
974331197849
721971572596
902469653832
936157710917
714588060426
276939435899
393954173900
692525720126
762289367234
1...

output:

6cad0f33-b1bd-3a3e-1a8d-c4af23adfcbf
OK
58
20 21 22 19 23 18 24 17 25 26 27 16 28 29 15 30 31 14 32 13 33 34 35 12 36 37 11 38 39 10 40 41 42 9 43 8 44 7 45 6 46 47 48 49 5 50 51 4 52 3 53 2 54 1 55 56 57 0
54
17 18 16 19 15 20 21 14 22 13 23 12 24 11 25 10 26 9 27 8 28 29 7 30 31 6 32 33 34 5 35 36...

result:

ok 

Test #6:

score: 90
Accepted
time: 139ms
memory: 4036kb

input:

a92b3f80-b312-8377-273c-3916024d7f2a
100
330061280882697
570108406837011
246465711199350
844437948491708
542197441405836
481743322695013
913237337833838
634038564781156
969749245791701
445335878892049
722391184659757
25600568975288
304176471716316
934030664268458
770565383569314
38589802113902
56387...

output:

6cad0f33-b1bd-3a3e-1a8d-c4af23adfcbf
OK
65
17 18 19 16 20 21 15 22 14 23 24 25 26 27 13 28 12 29 30 31 32 33 34 11 35 10 36 37 38 39 40 9 41 42 8 43 7 44 45 46 6 47 5 48 49 4 50 51 3 52 2 53 54 55 56 57 58 59 60 61 1 62 63 64 0
69
20 21 22 23 24 25 26 19 27 18 28 29 17 30 31 32 33 34 35 16 36 37 15 ...

result:

ok 

Test #7:

score: 87.6667
Acceptable Answer
time: 155ms
memory: 3792kb

input:

a92b3f80-b312-8377-273c-3916024d7f2a
100
9808783958425241
800256975993528789
891794666437715812
154809014071580277
262143300778136084
508038278751820218
855062810898478629
196129157832150290
519747744582635554
544132224659269080
335568667826635843
978219202156109836
887928188166976766
57068450616591...

output:

6cad0f33-b1bd-3a3e-1a8d-c4af23adfcbf
OK
79
26 27 28 29 25 30 31 24 32 23 33 34 22 35 21 36 37 38 20 39 40 41 42 43 19 44 45 46 18 47 48 17 49 16 50 15 51 14 52 53 13 54 12 55 11 56 57 58 59 60 10 61 62 9 63 64 65 8 66 7 67 6 68 5 69 4 70 71 3 72 73 74 2 75 1 76 77 78 0
92
33 34 32 35 31 36 37 38 39 ...

result:

points 0.97407407410

Test #8:

score: 90
Accepted
time: 141ms
memory: 3828kb

input:

a92b3f80-b312-8377-273c-3916024d7f2a
100
576460752303423488
576460752303423489
576460752303423490
576460752303423491
576460752303423492
576460752303423493
576460752303423494
576460752303423495
576460752303423496
576460752303423497
576460752303423498
576460752303423499
576460752303423500
576460752303...

output:

6cad0f33-b1bd-3a3e-1a8d-c4af23adfcbf
OK
59
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
60
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 ...

result:

ok 

Test #9:

score: 87
Acceptable Answer
time: 166ms
memory: 3848kb

input:

a92b3f80-b312-8377-273c-3916024d7f2a
100
999999999999999901
999999999999999902
999999999999999903
999999999999999904
999999999999999905
999999999999999906
999999999999999907
999999999999999908
999999999999999909
999999999999999910
999999999999999911
999999999999999912
999999999999999913
999999999999...

output:

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

result:

points 0.96666666670

Test #10:

score: 87
Acceptable Answer
time: 145ms
memory: 3880kb

input:

a92b3f80-b312-8377-273c-3916024d7f2a
100
333271685633113373
303681151173201623
185954994672690293
695000491456721509
680039555562404861
711731044985538439
725639770789026979
653124604194000671
716161846351295353
727816570890872159
566821251164212697
620956504691616073
845196440395453799
654653854021...

output:

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

result:

points 0.96666666670

Test #11:

score: 89.3333
Acceptable Answer
time: 145ms
memory: 3800kb

input:

a92b3f80-b312-8377-273c-3916024d7f2a
100
11260605527954640
3776579230632
1586488757700
753903936556020250
10601397297904140
810787108223734551
544021594614225000
609804018090927660
212587386929622705
334981274861463750
759012209987031
879302565815602500
156896254323644472
501935537823034315
23356411...

output:

6cad0f33-b1bd-3a3e-1a8d-c4af23adfcbf
OK
71
18 19 17 20 21 22 23 24 25 26 27 28 29 30 16 31 32 15 33 14 34 13 35 36 12 37 11 38 39 40 41 42 43 10 44 45 46 47 48 9 49 8 50 7 51 52 53 6 54 5 55 56 57 58 4 59 60 3 61 62 63 2 64 1 65 66 0 67 68 69 70
65
24 23 25 26 22 27 21 28 29 20 30 19 31 18 32 17 33 ...

result:

points 0.99259259260

Test #12:

score: 82
Acceptable Answer
time: 159ms
memory: 3820kb

input:

a92b3f80-b312-8377-273c-3916024d7f2a
100
450283905890997362
288230376151711743
298023223876953124
789730223053602815
558545864083284006
144115188075855871
150094635296999120
999999999999999999
505447028499293770
184884258895036415
665416609183179840
155568095557812223
437893890380859374
720575940379...

output:

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

result:

points 0.91111111110