QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#407846 | #4252. Permutation | zhaohaikun# | 98 | 1ms | 4076kb | C++20 | 3.5kb | 2024-05-09 12:52:33 | 2024-05-09 12:52:34 |
Judging History
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;
if (n % 3 == 2) return cc((n - 2) / 3) + 2;
return cc(n - 1) + 1;
}
vector <int> solve(ll n) {
if (n == 0) return vector <int> {};
F(i, 1, 5) {
if (n >= i && (n - i) % (i + 1) == 0) {
vector <int> ans = solve((n - i) / (i + 1));
int t = ans.size();
F(j, 1, i) ans.push_back(t + i - j);
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;
// debug << __builtin_popcount(n) << endl;
// F(i, 1, 60) {
// // vector <int> t(i);
// // F(j, 1, i) t[j - 1] = j - 1;
// // lim = min(1000, lim * i);
// // do {
// // F(j, 1, lim) {
// // shuffle(all(t), mrand);
// // ll v = calc(t);
// // // debug << v << endl;
// // if (n >= v) {
// // // debug << v << ' ' << cc(n - v) << ' ' << i << endl;
// // // vector <int> w = cc(n - v);
// // if (cc(n - v) + i < ans.size()) {
// // assert(false);
// // 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;
// ll t = n - ((1ll << i) - 1);
// if (t < 0) break;
// // debug << i << endl;
// if (cc(t) + i < ans.size()) {
// // debug << " ! " << cc(t) + i << endl;
// vector <int> w = solve(t);
// ans.clear();
// F(j, 1, i) ans.push_back(j - 1);
// for (int j: w) ans.push_back(j + w.size());
// }
// }
return ans;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 3728kb
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 4 3 2 1 0 3 1 0 2 4 2 1 3 0 3 0 1 2 4 1 0 3 2 5 3 2 1 0 4 6 4 3 2 1 5 0 4 1 0 2 3 5 2 1 3 4 0 5 2 1 3 0 4 6 3 2 1 0 5 4 4 0 1 2 3 5 1 2 3 4 0 5 1 0 3 2 4 6 2 1 4 3 5 0 6 3 2 1 0 4 5 6 2 1 3 0 5 4 7 4 3 2 1 5 0 6 8 5 4 3 2 6 1 7 0 5 1 0 2 3 4 8 ...
result:
ok
Subtask #2:
score: 88
Acceptable Answer
Test #2:
score: 90
Accepted
time: 1ms
memory: 3728kb
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 4 3 6 5 7 8 2 10 9 12 11 13 14 1 18 17 16 15 19 0 21 20 26 8 7 9 6 10 11 5 12 4 13 3 17 16 15 14 19 18 20 2 22 21 23 1 24 25 0 22 4 3 2 1 6 5 8 7 10 9 11 12 13 0 17 16 15 14 19 18 21 20 24 8 7 6 5 9 4 10 3 11 2 13 12 15 14 17 16 18 1 22 21 20 19 23 0 16 3 2...
result:
ok
Test #3:
score: 90
Accepted
time: 1ms
memory: 3716kb
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 48 12 11 13 10 15 14 16 9 20 19 18 17 21 8 22 7 24 23 26 25 28 27 29 6 30 31 5 32 4 36 35 34 33 37 38 39 40 3 41 2 42 1 44 43 46 45 47 0 46 11 10 12 9 14 13 15 8 19 18 17 16 20 7 21 6 23 22 25 24 27 26 28 5 29 30 4 31 3 35 34 33 32 36 37 38 39 2 40 1 41 0 43 4...
result:
ok
Test #4:
score: 89.3333
Acceptable Answer
time: 1ms
memory: 3816kb
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 92 22 21 20 19 23 18 24 17 25 16 26 27 28 15 30 29 32 31 33 14 37 36 35 34 38 13 42 41 40 39 43 44 12 45 11 46 10 50 49 48 47 51 52 9 56 55 54 53 57 58 59 60 8 62 61 63 7 67 66 65 64 68 6 69 5 71 70 72 4 74 73 75 76 77 78 3 79 80 81 82 2 86 85 84 83 87 88 1 90...
result:
points 0.99259259260
Test #5:
score: 90
Accepted
time: 0ms
memory: 3892kb
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 52 7 6 8 5 10 9 11 12 13 4 14 15 16 17 18 19 3 20 21 22 2 24 23 26 25 28 27 30 29 32 31 33 34 35 36 37 1 41 40 39 38 45 44 43 42 46 47 0 51 50 49 48 48 4 3 5 6 7 8 2 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 25 26 27 1 31 30 29 28 33 32 34 35 36 37 38 39 ...
result:
ok
Test #6:
score: 90
Accepted
time: 1ms
memory: 4076kb
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 67 13 12 11 10 17 16 15 14 18 19 9 20 21 22 8 23 7 24 25 26 6 27 5 31 30 29 28 32 33 4 34 3 38 37 36 35 40 39 41 42 2 44 43 45 46 47 48 1 50 49 51 52 53 54 55 56 57 58 59 60 61 62 0 64 63 66 65 75 17 16 15 14 18 13 20 19 21 12 25 24 23 22 26 11 28 27 29 10 30 ...
result:
ok
Test #7:
score: 88
Acceptable Answer
time: 1ms
memory: 3844kb
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 76 11 10 13 12 14 9 16 15 18 17 20 19 21 22 8 24 23 25 26 7 27 28 29 30 6 32 31 34 33 35 36 5 38 37 40 39 41 42 43 4 47 46 45 44 51 50 49 48 52 53 54 55 3 59 58 57 56 60 61 2 65 64 63 62 67 66 68 1 72 71 70 69 73 74 75 0 90 18 17 19 16 20 21 15 25 24 23 22 26 ...
result:
points 0.97777777780
Test #8:
score: 88.3333
Acceptable Answer
time: 1ms
memory: 3996kb
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 92 22 21 20 19 23 18 24 17 25 16 26 27 28 15 30 29 32 31 33 14 37 36 35 34 38 13 42 41 40 ...
result:
points 0.98148148150
Test #9:
score: 89
Acceptable Answer
time: 1ms
memory: 3796kb
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 91 15 14 13 12 17 16 18 11 22 21 20 19 24 23 25 26 27 10 29 28 30 31 9 32 33 34 35 8 39 38 37 36 41 40 42 43 7 47 46 45 44 51 50 49 48 52 53 6 54 5 58 57 56 55 60 59 61 62 4 64 63 66 65 67 3 68 69 2 73 72 71 70 75 74 76 1 80 79 78 77 84 83 82 81 86 85 88 87 89...
result:
points 0.98888888890
Test #10:
score: 88.3333
Acceptable Answer
time: 1ms
memory: 3836kb
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 86 18 17 16 15 19 14 23 22 21 20 24 25 13 26 12 30 29 28 27 32 31 34 33 35 36 11 38 37 39 40 10 44 43 42 41 45 9 47 46 48 8 50 49 52 51 53 54 7 55 56 6 57 5 59 58 60 4 62 61 64 63 65 66 67 3 69 68 71 70 73 72 74 75 76 2 78 77 80 79 82 81 83 1 84 85 0 86 16 15 ...
result:
points 0.98148148150
Test #11:
score: 89
Acceptable Answer
time: 0ms
memory: 3992kb
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 75 13 12 11 10 17 16 15 14 18 19 9 23 22 21 20 25 24 26 8 28 27 29 30 7 32 31 33 34 35 36 37 6 38 39 5 41 40 43 42 44 4 46 45 47 3 49 48 51 50 53 52 54 55 56 57 2 58 59 1 60 0 64 63 62 61 66 65 68 67 70 69 71 72 73 74 57 12 11 10 9 13 14 15 8 17 16 18 7 22 21 ...
result:
points 0.98888888890
Test #12:
score: 88.3333
Acceptable Answer
time: 1ms
memory: 3800kb
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 81 12 11 10 9 16 15 14 13 17 18 8 20 19 22 21 24 23 25 26 27 7 29 28 31 30 33 32 34 35 6 36 37 38 39 40 41 5 45 44 43 42 46 47 48 49 4 51 50 52 3 56 55 54 53 57 58 59 2 61 60 63 62 65 64 67 66 68 69 70 1 74 73 72 71 76 75 77 78 79 0 80 90 21 20 19 18 22 17 23 ...
result:
points 0.98148148150