Skip to content

Commit 1db7e8e

Browse files
committed
More fixes for -Wconversion
1 parent c7aba2b commit 1db7e8e

File tree

16 files changed

+58
-56
lines changed

16 files changed

+58
-56
lines changed

cp-algo/math/combinatorics.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace cp_algo::math {
2424
static std::vector<T> F(maxn);
2525
static bool init = false;
2626
if(!init) {
27-
int t = std::min<int64_t>(T::mod(), maxn) - 1;
27+
int t = (int)std::min<int64_t>(T::mod(), maxn) - 1;
2828
F[t] = T(1) / fact<T>(t);
2929
for(int i = t - 1; i >= 0; i--) {
3030
F[i] = F[i + 1] * T(i + 1);

cp-algo/math/poly.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ namespace cp_algo::math {
462462
if(is_zero()) {
463463
return *this;
464464
}
465-
int n = p.size();
465+
size_t n = p.size();
466466
std::vector<poly_t> tree(4 * n);
467467
build(tree, 1, begin(p), end(p));
468468
return to_newton(tree, 1, begin(p), end(p));
@@ -481,7 +481,7 @@ namespace cp_algo::math {
481481
}
482482

483483
std::vector<T> eval(std::vector<T> x) { // evaluate polynomial in (x1, ..., xn)
484-
int n = x.size();
484+
size_t n = x.size();
485485
if(is_zero()) {
486486
return std::vector<T>(n, T(0));
487487
}
@@ -502,7 +502,7 @@ namespace cp_algo::math {
502502
}
503503

504504
static auto inter(std::vector<T> x, std::vector<T> y) { // interpolates minimum polynomial from (xi, yi) pairs
505-
int n = x.size();
505+
size_t n = x.size();
506506
std::vector<poly_t> tree(4 * n);
507507
return build(tree, 1, begin(x), end(x)).deriv().inter(tree, 1, begin(y), end(y));
508508
}
@@ -600,11 +600,11 @@ namespace cp_algo::math {
600600
// Find [x^k] P / Q
601601
static T kth_rec_inplace(poly_t &P, poly_t &Q, int64_t k) {
602602
while(k > Q.deg()) {
603-
int n = Q.a.size();
603+
size_t n = Q.a.size();
604604
auto [Q0, Q1] = Q.bisect();
605605
auto [P0, P1] = P.bisect();
606606

607-
int N = fft::com_size((n + 1) / 2, (n + 1) / 2);
607+
size_t N = fft::com_size((n + 1) / 2, (n + 1) / 2);
608608

609609
auto Q0f = fft::dft<T>(Q0.a, N);
610610
auto Q1f = fft::dft<T>(Q1.a, N);
@@ -619,7 +619,7 @@ namespace cp_algo::math {
619619
}
620620
k /= 2;
621621
}
622-
return (P *= Q.inv_inplace(Q.deg() + 1))[k];
622+
return (P *= Q.inv_inplace(Q.deg() + 1))[(int)k];
623623
}
624624
static T kth_rec(poly_t const& P, poly_t const& Q, int64_t k) {
625625
return kth_rec_inplace(poly_t(P), poly_t(Q), k);
@@ -638,7 +638,7 @@ namespace cp_algo::math {
638638
return poly::impl::inv_inplace(*this, k, n);
639639
}
640640
poly_t inv(int64_t k, size_t n) const {
641-
return poly_t(*this).inv_inplace(k, n);;
641+
return poly_t(*this).inv_inplace(k, n);
642642
}
643643

644644
// compute A(B(x)) mod x^n in O(n^2)

cp-algo/math/poly/impl/div.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ namespace cp_algo::math::poly::impl {
8686
auto q0f = fft::dft<base>(q0.a, N);
8787
auto q1f = fft::dft<base>(q1.a, N);
8888
auto qqf = fft::dft<base>(qq.a, N);
89-
int M = q0.deg() + (n + 1) / 2;
89+
size_t M = q0.deg() + (n + 1) / 2;
9090
std::vector<base> A(M), B(M);
9191
q0f.mul(qqf, A, M);
9292
q1f.mul_inplace(qqf, B, M);

cp-algo/math/poly/impl/euclid.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ namespace cp_algo::math::poly::impl {
1919
template<typename poly>
2020
gcd_result<poly> half_gcd(poly &&A, poly &&B) {
2121
assert(A.deg() >= B.deg());
22-
int m = size(A.a) / 2;
23-
if(B.deg() < m) {
22+
size_t m = size(A.a) / 2;
23+
if(B.deg() < (int)m) {
2424
return {};
2525
}
2626
auto [ai, R] = A.divmod(B);
2727
std::tie(A, B) = {B, R};
2828
std::list a = {ai};
2929
auto T = -linfrac(ai).adj();
3030

31-
auto advance = [&](int k) {
31+
auto advance = [&](size_t k) {
3232
auto [ak, Tk] = half_gcd(A.div_xk(k), B.div_xk(k));
3333
a.splice(end(a), ak);
3434
T.prepend(Tk);
@@ -83,7 +83,7 @@ namespace cp_algo::math::poly::impl {
8383
auto [a, Tr] = full_gcd(R1, R2);
8484
a.emplace_back();
8585
auto pref = begin(a);
86-
for(int delta = d - a.front().deg(); delta >= 0; pref++) {
86+
for(int delta = (int)d - a.front().deg(); delta >= 0; pref++) {
8787
delta -= pref->deg() + next(pref)->deg();
8888
}
8989
return convergent(begin(a), pref).a;

cp-algo/structures/fenwick.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ namespace cp_algo::structures {
6363
// Assumes prefix_fold is monotonic
6464
// returns [x, prefix_fold(x)]
6565
auto prefix_lower_bound(T k) const {
66-
int x = 0;
66+
size_t x = 0;
6767
T pref = {};
6868
for(size_t i = std::bit_floor(n); i; i /= 2) {
6969
if(x + i <= n && op(pref, data[x + i]) <= k) {

cp-algo/structures/fenwick_set.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace cp_algo::structures {
4343
if(order >= sz) {
4444
return -1;
4545
}
46-
auto [x, pref] = Base::prefix_lower_bound(order);
46+
auto [x, pref] = Base::prefix_lower_bound((int)order);
4747
return x * word + kth_set_bit(bits.word(x), order - pref);
4848
}
4949
size_t lower_bound(size_t x) const {

cp-algo/structures/segtree.hpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
11
#ifndef CP_ALGO_STRUCTURES_SEGMENT_TREE_HPP
22
#define CP_ALGO_STRUCTURES_SEGMENT_TREE_HPP
33
#include <vector>
4+
#include <numeric>
45
namespace cp_algo::structures {
56
template<typename meta>
67
struct segtree_t {
7-
const int N;
8+
const size_t N;
89
std::vector<meta> _meta;
910

10-
segtree_t(int n): N(n), _meta(4 * N) {}
11+
segtree_t(size_t n): N(n), _meta(4 * N) {}
1112

1213
segtree_t(std::vector<meta> leafs): N(size(leafs)), _meta(4 * N) {
1314
build(leafs);
1415
}
1516

16-
void pull(int v, int l, int r) {
17+
void pull(size_t v, size_t l, size_t r) {
1718
if(r - l > 1) {
1819
_meta[v].pull(_meta[2 * v], _meta[2 * v + 1], l, r);
1920
}
2021
}
2122

22-
void push(int v, int l, int r) {
23+
void push(size_t v, size_t l, size_t r) {
2324
if(r - l > 1) {
2425
_meta[v].push(&_meta[2 * v], &_meta[2 * v + 1], l, r);
2526
} else {
2627
_meta[v].push(nullptr, nullptr, l, r);
2728
}
2829
}
2930

30-
void build(auto &a, int v, size_t l, size_t r) {
31+
void build(auto &a, size_t v, size_t l, size_t r) {
3132
if(r - l == 1) {
3233
if(l < size(a)) {
3334
_meta[v] = a[l];
3435
}
3536
} else {
36-
size_t m = (l + r) / 2;
37+
size_t m = std::midpoint(l, r);
3738
build(a, 2 * v, l, m);
3839
build(a, 2 * v + 1, m, r);
3940
pull(v, l, r);
@@ -44,15 +45,15 @@ namespace cp_algo::structures {
4445
build(a, 1, 0, N);
4546
}
4647

47-
void exec_on_segment(int a, int b, auto func, auto proceed, auto stop, int v, int l, int r) {
48+
void exec_on_segment(size_t a, size_t b, auto func, auto proceed, auto stop, size_t v, size_t l, size_t r) {
4849
push(v, l, r);
4950
if(r <= a || b <= l || stop(_meta[v])) {
5051
return;
5152
} else if(a <= l && r <= b && proceed(_meta[v])) {
5253
func(_meta[v]);
5354
push(v, l, r);
5455
} else {
55-
int m = (l + r) / 2;
56+
size_t m = std::midpoint(l, r);
5657
exec_on_segment(a, b, func, proceed, stop, 2 * v, l, m);
5758
exec_on_segment(a, b, func, proceed, stop, 2 * v + 1, m, r);
5859
pull(v, l, r);
@@ -62,11 +63,11 @@ namespace cp_algo::structures {
6263
static constexpr auto default_true = [](auto const&){return true;};
6364
static constexpr auto default_false = [](auto const&){return false;};
6465

65-
void exec_on_segment(int a, int b, auto func, auto proceed, auto stop) {
66+
void exec_on_segment(size_t a, size_t b, auto func, auto proceed, auto stop) {
6667
exec_on_segment(a, b, func, proceed, stop, 1, 0, N);
6768
}
6869

69-
void exec_on_segment(int a, int b, auto func) {
70+
void exec_on_segment(size_t a, size_t b, auto func) {
7071
exec_on_segment(a, b, func, default_true, default_false);
7172
}
7273
};

cp-algo/structures/segtree/metas/affine.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace cp_algo::structures::segtree::metas {
1414
affine_meta() {}
1515
affine_meta(base sum): sum(sum) {}
1616

17-
void push(meta *L, meta *R, int l, int r) override {
17+
void push(meta *L, meta *R, size_t l, size_t r) override {
1818
if(to_push.a != 1 || to_push.b != 0) {
1919
sum = to_push.a * sum + to_push.b * (r - l);
2020
if(r - l > 1) {
@@ -25,7 +25,7 @@ namespace cp_algo::structures::segtree::metas {
2525
}
2626
}
2727

28-
void pull(meta const& L, meta const& R, int, int) override {
28+
void pull(meta const& L, meta const& R, size_t, size_t) override {
2929
sum = L.sum + R.sum;
3030
}
3131
};
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#ifndef CP_ALGO_STRUCTURES_SEGMENT_TREE_METAS_BASE_HPP
22
#define CP_ALGO_STRUCTURES_SEGMENT_TREE_METAS_BASE_HPP
3+
#include <cstddef>
34
namespace cp_algo::structures::segtree::metas {
45
template<typename derived_meta>
56
struct base_meta {
67
using meta = derived_meta;
7-
virtual void pull(meta const&, meta const&, int, int) {};
8-
virtual void push(meta*, meta*, int, int) {};
8+
virtual void pull(meta const&, meta const&, size_t, size_t) {};
9+
virtual void push(meta*, meta*, size_t, size_t) {};
910
};
1011
}
1112
#endif // CP_ALGO_STRUCTURES_SEGMENT_TREE_METAS_BASE_HPP

cp-algo/structures/segtree/metas/chmin_chmax_add.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace cp_algo::structures::segtree::metas {
1414
template<typename Comp>
1515
struct data {
1616
int64_t val;
17-
int64_t count = 1;
17+
size_t count = 1;
1818
int64_t second = std::max(inf, -inf, comp);
1919
static const Comp comp;
2020

@@ -50,7 +50,7 @@ namespace cp_algo::structures::segtree::metas {
5050
chmin_chmax_sum_meta() {}
5151
chmin_chmax_sum_meta(int64_t val): sum(val) {}
5252

53-
void pull(meta const& L, meta const& R, int, int) override {
53+
void pull(meta const& L, meta const& R, size_t, size_t) override {
5454
sum = L.sum + R.sum;
5555
mn = L.mn.combine(R.mn);
5656
mx = L.mx.combine(R.mx);
@@ -62,7 +62,7 @@ namespace cp_algo::structures::segtree::metas {
6262
t.chmax = std::clamp(t.chmax, chmax, chmin);
6363
}
6464

65-
void push(meta* L, meta* R, int l, int r) override {
65+
void push(meta* L, meta* R, size_t l, size_t r) override {
6666
if(r - l > 1) {
6767
push(*L);
6868
push(*R);

0 commit comments

Comments
 (0)