blob: 1b3e8033acdc1bbbca121b7cc0084ddf09acd81e (
plain)
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
|
#include "../util.h"
#include <math/kthperm.cpp>
void stress_test() {
ll queries = 0;
for (ll i = 0; i < 10'000; i++) {
int n = Random::integer<int>(1, 100);
vector<ll> expected(n);
iota(begin(expected), end(expected), 0);
ll k = 0;
do {
auto got = kthperm(n, k);
if (got != expected) cerr << "error" << FAIL;
k++;
} while (k < 100 && ranges::next_permutation(expected).found);
queries += n;
}
cerr << "tested queries: " << queries << endl;
}
constexpr int N = 500'000;
void performance_test() {
timer t;
t.start();
auto got = kthperm(N, 4'168'751'907'498'170ll);
t.stop();
hash_t hash = 0;
for (ll i = 0; i < N; i++) hash += i * got[i];
if (t.time > 500) cerr << "too slow: " << t.time << FAIL;
cerr << "tested performance: " << t.time << "ms (hash: " << hash << ")" << endl;
}
int main() {
stress_test();
performance_test();
}
|