Skip to content

Commit

Permalink
Merge pull request #92 from NyaanNyaan/add_verify
Browse files Browse the repository at this point in the history
add verify
  • Loading branch information
NyaanNyaan authored Sep 2, 2023
2 parents ea6a267 + c8be119 commit abef907
Show file tree
Hide file tree
Showing 21 changed files with 886 additions and 140 deletions.
19 changes: 13 additions & 6 deletions .verify-helper/timestamps.remote.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"verify/verify-aoj-other/aoj-1130-DG-bfs.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-aoj-other/aoj-1377.test.cpp": "2023-08-27 10:14:06 +0900",
"verify/verify-aoj-other/aoj-1613.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-aoj-other/aoj-2171-bigrational.test.cpp": "2023-08-10 14:06:55 +0900",
"verify/verify-aoj-other/aoj-2171-bigrational.test.cpp": "2023-09-02 23:13:20 +0900",
"verify/verify-aoj-other/aoj-2171.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-aoj-other/aoj-2891.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-aoj-other/aoj-2945-01bfs.test.cpp": "2023-08-10 13:25:59 +0900",
Expand All @@ -80,6 +80,7 @@
"verify/verify-unit-test/bigint.test.cpp": "2023-08-10 14:06:55 +0900",
"verify/verify-unit-test/bigint2.test.cpp": "2023-08-10 14:25:31 +0900",
"verify/verify-unit-test/bigint3.test.cpp": "2023-08-10 14:25:31 +0900",
"verify/verify-unit-test/bigrational.test.cpp": "2023-09-02 22:21:41 +0900",
"verify/verify-unit-test/bitset-find-prev.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-unit-test/complex-fft.test.cpp": "2023-08-10 14:06:55 +0900",
"verify/verify-unit-test/composite-exp.test.cpp": "2023-08-31 20:44:07 +0900",
Expand Down Expand Up @@ -127,7 +128,7 @@
"verify/verify-unit-test/primitive-root.test.cpp": "2023-08-31 20:44:07 +0900",
"verify/verify-unit-test/radix-heap.test.cpp": "2023-08-10 14:06:55 +0900",
"verify/verify-unit-test/radix-sort.test.cpp": "2023-08-10 14:25:31 +0900",
"verify/verify-unit-test/rational-number.test.cpp": "2023-08-10 14:06:55 +0900",
"verify/verify-unit-test/rational-number.test.cpp": "2023-09-02 22:21:41 +0900",
"verify/verify-unit-test/rbst-segment-tree.test.cpp": "2023-08-10 14:25:31 +0900",
"verify/verify-unit-test/rbst-sequence.test.cpp": "2023-08-10 14:06:55 +0900",
"verify/verify-unit-test/relaxed-convolution.test.cpp": "2023-08-31 20:44:07 +0900",
Expand All @@ -149,6 +150,7 @@
"verify/verify-yosupo-ds/yosupo-associative-array-rbstseg.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yosupo-ds/yosupo-associative-array-unerasable-hashmap.test.cpp": "2023-08-27 10:14:06 +0900",
"verify/verify-yosupo-ds/yosupo-binary-trie.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yosupo-ds/yosupo-deque-operate-all-composite.test.cpp": "2023-09-02 22:21:41 +0900",
"verify/verify-yosupo-ds/yosupo-dynamic-li-chao-tree.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yosupo-ds/yosupo-dynamic-sequence-range-affine-range-sum-splay.test.cpp": "2023-08-10 18:41:15 +0900",
"verify/verify-yosupo-ds/yosupo-dynamic-sequence-range-affine-range-sum-treap.test.cpp": "2023-08-10 14:25:31 +0900",
Expand Down Expand Up @@ -183,6 +185,8 @@
"verify/verify-yosupo-ds/yosupo-predecessor-problem.test.cpp": "2023-08-10 14:25:31 +0900",
"verify/verify-yosupo-ds/yosupo-procedessor-problem-rbstseg.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yosupo-ds/yosupo-range-add-range-sum-linkcuttree.test.cpp": "2023-08-10 18:41:15 +0900",
"verify/verify-yosupo-ds/yosupo-range-affine-point-get-2.test.cpp": "2023-09-02 22:21:41 +0900",
"verify/verify-yosupo-ds/yosupo-range-affine-point-get.test.cpp": "2023-09-02 22:21:41 +0900",
"verify/verify-yosupo-ds/yosupo-range-affine-range-sum-dynamic-segtree.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yosupo-ds/yosupo-range-affine-range-sum-rbstseg.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yosupo-ds/yosupo-range-affine-sqdec.test.cpp": "2023-08-10 13:25:59 +0900",
Expand All @@ -194,7 +198,7 @@
"verify/verify-yosupo-ds/yosupo-static-range-inversion-query-2.test.cpp": "2023-08-10 14:25:31 +0900",
"verify/verify-yosupo-ds/yosupo-static-range-inversions-query.test.cpp": "2023-08-10 14:25:31 +0900",
"verify/verify-yosupo-ds/yosupo-static-rmq.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yosupo-ds/yosupo-swag.test.cpp": "2023-08-10 14:25:31 +0900",
"verify/verify-yosupo-ds/yosupo-swag.test.cpp": "2023-09-02 22:21:41 +0900",
"verify/verify-yosupo-ds/yosupo-vertex-add-path-sum-euler-tour.test.cpp": "2023-08-10 14:25:31 +0900",
"verify/verify-yosupo-ds/yosupo-vertex-add-path-sum.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yosupo-ds/yosupo-vertex-add-subtree-sum-dst-on-tree.test.cpp": "2023-08-10 14:25:31 +0900",
Expand Down Expand Up @@ -267,6 +271,7 @@
"verify/verify-yosupo-math/yosupo-counting-primes-3.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yosupo-math/yosupo-counting-primes-4.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yosupo-math/yosupo-counting-primes.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yosupo-math/yosupo-determinant-arbitrary-mod.test.cpp": "2023-09-02 22:21:41 +0900",
"verify/verify-yosupo-math/yosupo-determinant-matrixlib.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yosupo-math/yosupo-determinant-of-matrix-bbla.test.cpp": "2023-08-31 20:44:07 +0900",
"verify/verify-yosupo-math/yosupo-determinant-of-sparse-matrix-bbla.test.cpp": "2023-08-31 20:44:07 +0900",
Expand Down Expand Up @@ -294,6 +299,7 @@
"verify/verify-yosupo-math/yosupo-primality-test.test.cpp": "2023-08-10 14:25:31 +0900",
"verify/verify-yosupo-math/yosupo-prime-enumerate-sieve.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yosupo-math/yosupo-prime-table.test.cpp": "2023-08-10 14:25:31 +0900",
"verify/verify-yosupo-math/yosupo-primitive-root.test.cpp": "2023-09-02 22:21:41 +0900",
"verify/verify-yosupo-math/yosupo-sparse-determinant.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yosupo-math/yosupo-stern-brocot-tree.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yosupo-math/yosupo-subset-convolution-fast.test.cpp": "2023-08-10 14:25:31 +0900",
Expand Down Expand Up @@ -361,7 +367,7 @@
"verify/verify-yuki/yuki-0886.test.cpp": "2023-08-30 23:05:07 +0900",
"verify/verify-yuki/yuki-0890.test.cpp": "2023-08-30 23:05:07 +0900",
"verify/verify-yuki/yuki-0896.test.cpp": "2023-08-30 23:05:07 +0900",
"verify/verify-yuki/yuki-0952.test.cpp": "2023-08-10 14:06:55 +0900",
"verify/verify-yuki/yuki-0952.test.cpp": "2023-09-02 22:21:41 +0900",
"verify/verify-yuki/yuki-0963-circular.test.cpp": "2023-08-31 20:44:07 +0900",
"verify/verify-yuki/yuki-0963.test.cpp": "2023-08-31 20:44:07 +0900",
"verify/verify-yuki/yuki-1080.test.cpp": "2023-08-31 20:44:07 +0900",
Expand Down Expand Up @@ -396,11 +402,12 @@
"verify/verify-yuki/yuki-1786.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yuki/yuki-1789.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yuki/yuki-1875.test.cpp": "2023-08-31 20:44:07 +0900",
"verify/verify-yuki/yuki-1939-sparse-pow.test.cpp": "2023-09-02 22:21:41 +0900",
"verify/verify-yuki/yuki-1939.test.cpp": "2023-08-31 20:44:07 +0900",
"verify/verify-yuki/yuki-2012.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yuki/yuki-2231.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yuki/yuki-2262.test.cpp": "2023-08-12 16:25:29 +0900",
"verify/verify-yuki/yuki-2266.test.cpp": "2023-08-12 16:25:29 +0900",
"verify/verify-yuki/yuki-2262.test.cpp": "2023-09-02 22:21:41 +0900",
"verify/verify-yuki/yuki-2266.test.cpp": "2023-09-02 22:21:41 +0900",
"verify/verify-yuki/yuki-2281.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yuki/yuki-2333.test.cpp": "2023-08-10 13:25:59 +0900",
"verify/verify-yuki/yuki-helloworld.test.cpp": "2023-08-10 13:25:59 +0900"
Expand Down
58 changes: 58 additions & 0 deletions data-structure/slide-window-aggregation-deque.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#pragma once

#include <vector>
using namespace std;

template <typename T, typename F>
struct SlideWindowAggregationDeque {
vector<T> a0, a1, r0, r1;
F f;
T I;

SlideWindowAggregationDeque(F _f, T _i) : f(_f), I(_i) {}

private:
T get0() const { return r0.empty() ? I : r0.back(); }
T get1() const { return r1.empty() ? I : r1.back(); }

void push0(const T &x) {
a0.push_back(x);
r0.push_back(f(x, get0()));
}
void push1(const T &x) {
a1.push_back(x);
r1.push_back(f(get1(), x));
}
void rebalance() {
int n = a0.size() + a1.size();
int s0 = n / 2 + (a0.empty() ? n % 2 : 0);
vector<T> a{a0};
reverse(begin(a), end(a));
copy(begin(a1), end(a1), back_inserter(a));
a0.clear(), r0.clear();
a1.clear(), r1.clear();
for (int i = s0 - 1; i >= 0; i--) push0(a[i]);
for (int i = s0; i < n; i++) push1(a[i]);
}

public:
void push_front(const T &t) { push0(t); }
void push_back(const T &t) { push1(t); }
T front() const { return a0.empty() ? a1.front() : a0.back(); }
T back() const { return a1.empty() ? a0.front() : a1.back(); }
void pop_front() {
if (a0.empty()) rebalance();
assert(!a0.empty());
a0.pop_back(), r0.pop_back();
}
void pop_back() {
if (a1.empty()) rebalance();
assert(!a1.empty());
a1.pop_back(), r1.pop_back();
}
T query() { return f(get0(), get1()); }
};

/**
* @brief Slide Window Aggrigation (deque)
*/
28 changes: 15 additions & 13 deletions data-structure/slide-window-aggregation.hpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
#pragma once

#include <vector>
using namespace std;

template <typename T, typename F>
struct SlideWindowAggregation {
stack<T> a0, a1;
stack<T> r0, r1;
vector<T> a0, a1, r0, r1;
F f;
T I, f0, f1;

SlideWindowAggregation(F f_, T I_) : f(f_), I(I_), f0(I_), f1(I_) {}
SlideWindowAggregation(F _f, T _i) : f(_f), I(_i), f0(_i), f1(_i) {}

private:
void push_s0(const T &x) {
a0.push(x);
r0.push(f0 = f(x, f0));
a0.push_back(x);
r0.push_back(f0 = f(x, f0));
}
void push_s1(const T &x) {
a1.push(x);
r1.push(f1 = f(f1, x));
a1.push_back(x);
r1.push_back(f1 = f(f1, x));
}
void transfer() {
while (!a1.empty()) {
push_s0(a1.top());
a1.pop();
push_s0(a1.back());
a1.pop_back();
}
while (!r1.empty()) r1.pop();
while (!r1.empty()) r1.pop_back();
f1 = I;
}

Expand All @@ -38,9 +40,9 @@ struct SlideWindowAggregation {
}
void pop() {
if (a0.empty()) transfer();
a0.pop();
r0.pop();
f0 = r0.empty() ? I : r0.top();
a0.pop_back();
r0.pop_back();
f0 = r0.empty() ? I : r0.back();
}
T query() { return f(f0, f1); }
};
Expand Down
2 changes: 1 addition & 1 deletion dp/monge-d-edge-shortest-path-enumerate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ vector<long long> enumerate_monge_d_edge_shortest_path(
vector<T> dp(N + 1, INF);
dp[0] = 0;
for (int d = 1; d <= N; d++) {
vector<int> midx = monotone_minima<T>(N + 1, [&](int j, int i) -> T {
vector<int> midx = monotone_minima<T>(N + 1, N + 1, [&](int j, int i) -> T {
return i < j ? dp[i] + f(i, j) : INF;
});
for (int i = N; i >= d; i--) dp[i] = dp[midx[i]] + f(midx[i], i);
Expand Down
25 changes: 18 additions & 7 deletions dp/monotone-minima.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,38 @@ using namespace std;

// NxN 行列がある
// m_i := argmin_j (A_{i,j}) が単調増加であるときに m_i を列挙する
// A(i, j) : A[i][j] を返す関数
template <typename T>
vector<int> monotone_minima(int N, const function<T(int, int)>& A) {
// f(i, j, k) :
// A[i][j] と A[i][k] を比較 (j < k が保証されている)
// A[i][j] <= A[i][k] のとき true を返す関数を入れる (等号はどちらでもよい)
vector<int> monotone_minima(int N, int M,
const function<bool(int, int, int)>& f) {
vector<int> res(N);
auto dfs = [&](auto rc, int is, int ie, int l, int r) -> void {
if (is == ie) return;
int i = (is + ie) / 2;
int m = l;
T fim = A(i, m);
for (int k = l + 1; k < r; k++) {
T fik = A(i, k);
if (fik < fim) fim = fik, m = k;
if (!f(i, m, k)) m = k;
}
res[i] = m;
rc(rc, is, i, l, m + 1);
rc(rc, i + 1, ie, m, r);
};
dfs(dfs, 0, N, 0, N);
dfs(dfs, 0, N, 0, M);
return res;
}

// NxM 行列がある
// m_i := argmin_j (A_{i,j}) が単調増加であるときに m_i を列挙する
// A(i, j) : A[i][j] を返す関数
template <typename T>
vector<int> monotone_minima(int N, int M, const function<T(int, int)>& A) {
function<bool(int, int, int)> f = [&](int i, int j, int k) -> bool {
return A(i, j) <= A(i, k);
};
return monotone_minima(N, M, f);
}

/**
* @brief monotone minima
*/
55 changes: 55 additions & 0 deletions marathon/multi-armed-bandit.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <algorithm>
#include <cassert>
#include <cmath>
#include <numeric>
#include <vector>
using namespace std;

#include "../misc/rng.hpp"

// N 択, 報酬最大化
struct MultiArmedBandit {
MultiArmedBandit(int n)
: N(n), last(-1), iter(0), thres(N * 5), num(N), v(N), e(N), t(1) {}

int N, last;
long long iter, thres;
vector<long long> num;
vector<double> v, e;
double t;

int play() {
assert(last == -1);
iter++;
if (iter <= thres) return last = iter % N;

double s = accumulate(begin(e), end(e), 0.0);
double x = rnd() * s;
for (int i = 0; i < N; i++) {
if ((x -= e[i]) <= 0) return last = i;
}
return last = N - 1;
}

// 重み付け用の関数
double f(double x) { return exp(x / t); }

void reward(double y) {
assert(last != -1);
v[last] += y;
num[last] += 1;
e[last] = f(v[last] / num[last]);
last = -1;

static double u = 1.0;
static double du = 0.01;
// iter % thres == 0 になったら t を再決定
if (iter % thres == 0) {
u = max(0.7, u - du);
double average = accumulate(begin(v), end(v), 0.0) / thres;
t = average < 0.0 ? 1.0 : pow(average, u);
for (int i = 0; i < N; i++) e[i] = f(v[i] / num[i]);
}
}
int best() { return max_element(begin(e), end(e)) - begin(e); }
};
14 changes: 14 additions & 0 deletions math/bigint-all.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include "rational-binomial.hpp"
#include "rational-fps.hpp"
#include "rational.hpp"
//
#include "bigint-rational.hpp"
#include "bigint.hpp"
//
using mint = BigRational;
using vm = vector<mint>;
using vvm = vector<vm>;
using fps = FormalPowerSeries_rational<mint>;
Binomial_rational<mint> C;
26 changes: 26 additions & 0 deletions math/primitive-root-ll.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <algorithm>
#include <vector>
using namespace std;

#include "../internal/internal-math.hpp"
#include "../prime/fast-factorize.hpp"

long long primitive_root_ll(long long p) {
if (p == 2) return 1;
auto fs = factorize(p - 1);
sort(begin(fs), end(fs));
fs.erase(unique(begin(fs), end(fs)), end(fs));
for (int g = 2;; g++) {
int ok = 1;
for (auto& f : fs) {
if (internal::modpow<long long, __int128_t>(g, (p - 1) / f, p) == 1) {
ok = false;
break;
}
}
if (ok) return g;
}
exit(1);
}
Loading

0 comments on commit abef907

Please sign in to comment.