Skip to content

Commit

Permalink
change alot
Browse files Browse the repository at this point in the history
  • Loading branch information
MtSaka committed Jul 17, 2024
1 parent f56872d commit 96a09f1
Show file tree
Hide file tree
Showing 48 changed files with 90 additions and 62 deletions.
16 changes: 10 additions & 6 deletions math/number/prime-sieve.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#pragma once
#include "../../template/template.hpp"
template <typename T>
struct prime_sieve {
struct PrimeSieve {
private:
vector<T> mpf;
vector<T> primes;
prime_sieve(T n = 1e5) {

public:
PrimeSieve(T n = 200000) {
mpf.resize(n + 1, 0);
iota(mpf.begin(), mpf.end(), 0);
mpf[0] = mpf[1] = -1;
Expand All @@ -18,7 +21,7 @@ struct prime_sieve {
for (T i = 2; i <= n; i++)
if (mpf[i] == i) primes.push_back(i);
}
vector<pair<T, int>> factorize(T n) {
vector<pair<T, int>> factorize(T n) const {
vector<pair<T, int>> res;
T now = n;
while (now != 1) {
Expand All @@ -30,8 +33,9 @@ struct prime_sieve {
}
return res;
}
vector<T> get_primes() const { return primes; }
};
template <typename T>
template <typename T = ll>
struct IsPrime {
T MAX;
vector<bool> isprime;
Expand All @@ -42,8 +46,8 @@ struct IsPrime {
for (T j = i * i; j < MAX + 1; j += i) isprime[j] = false;
}
}
bool is_prime(T x) { return isprime[x]; }
vector<T> primes(T m = -1) {
bool is_prime(T x) const { return isprime[x]; }
vector<T> get_primes(T m = -1) const {
if (m == -1) m = MAX;
vector<T> res;
for (T i = 2; i < m + 1; i++)
Expand Down
14 changes: 8 additions & 6 deletions math/number/quotient-ranges.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
template <typename T>
vector<pair<T, pair<T, T>>> quotient_ranges(T n) {
vector<pair<T, pair<T, T>>> ans;
T m;
for (m = 1; m * m <= n; m++) {
ans.emplace_back(n / m, make_pair(m, m));
}
for (T i = m; i >= 1; i--) {
if (n / (i + 1) + 1 <= n / i && ans.back().second.second < n / i) ans.emplace_back(i, make_pair(n / (i + 1) + 1, n / i));
T sq = sqrtl(n);
if (sq * sq + sq <= n) sq++;
const T m = n / sq;
ans.reserve(m + sq - 1);
rep(i, 1, sq) ans.emplace_back(n / i, make_pair(i, i));
rrep(i, 1, m + 1) {
const T l = n / (i + 1) + 1, r = n / i;
ans.emplace_back(i, make_pair(l, r));
}
return ans;
}
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/ALDS1/ALDS1_1_C_1.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ int main() {
int q;
sc >> q;
int ans = 0;
while (q--) {
rep(q) {
int x;
sc >> x;
ans += is_prime(x);
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/CGL/CGL_1_A.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int main() {
geometry::point p1, p2;
sc >> p1 >> p2;
INT(q);
while (q--) {
rep(q) {
geometry::point q;
sc >> q;
auto ans = geometry::project(geometry::line(p1, p2), q);
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/CGL/CGL_1_B.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int main() {
geometry::point p1, p2;
sc >> p1 >> p2;
INT(q);
while (q--) {
rep(q) {
geometry::point p;
sc >> p;
auto ans = geometry::reflect(geometry::line(p1, p2), p);
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/CGL/CGL_1_C.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ int main() {
geometry::point p1, p2;
sc >> p1 >> p2;
INT(q);
while (q--) {
rep(q) {
geometry::point p;
sc >> p;
int dir = geometry::ccw(p, p1, p2);
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/CGL/CGL_2_A.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "../../../template/template.hpp"
int main() {
INT(q);
while (q--) {
rep(q) {
geometry::point p1, p2, q1, q2;
sc >> p1 >> p2 >> q1 >> q2;
geometry::line a(p1, p2), b(q1, q2);
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/CGL/CGL_2_B.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "../../../template/template.hpp"
int main() {
INT(q);
while (q--) {
rep(q) {
geometry::point p1, p2, q1, q2;
sc >> p1 >> p2 >> q1 >> q2;
geometry::segment a(p1, p2), b(q1, q2);
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/CGL/CGL_2_C.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "../../../template/template.hpp"
int main() {
INT(q);
while (q--) {
rep(q) {
geometry::point p1, p2, q1, q2;
sc >> p1 >> p2 >> q1 >> q2;
geometry::line a(p1, p2), b(q1, q2);
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/CGL/CGL_2_D.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "../../../template/template.hpp"
int main() {
INT(q);
while (q--) {
rep(q) {
geometry::point p1, p2, q1, q2;
sc >> p1 >> p2 >> q1 >> q2;
geometry::segment a(p1, p2), b(q1, q2);
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/CGL/CGL_3_C.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int main() {
geometry::polygon pol(n);
rep(i, n) sc >> pol[i];
INT(q);
while (q--) {
rep(q) {
geometry::point p;
sc >> p;
int ans = geometry::in_polygon(p, pol);
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/DSL/DSL_1_A.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ int main() {
int n, q;
sc >> n >> q;
UnionFind d(n);
while (q--) {
rep(q) {
int t, x, y;
sc >> t >> x >> y;
if (t == 0)
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/DSL/DSL_2_A.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
int main() {
INT(n, q);
RangeMinimumQuery<int, (1ull << 31) - 1> RMQ(n);
while (q--) {
rep(q) {
INT(t, x, y);
if (t == 0)
RMQ.set(x, y);
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/DSL/DSL_2_B.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
int main() {
INT(n, q);
BinaryIndexedTree<int> bit(n);
while (q--) {
rep(q) {
INT(t, x, y);
if (t)
print(bit.sum(x - 1, y));
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/DSL/DSL_2_B2.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
int main() {
INT(n, q);
RangeSumQuery<int> RSQ(n);
while (q--) {
rep(q) {
INT(t, a, b);
if (t == 0)
RSQ.apply(a - 1, b);
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/DSL/DSL_2_D.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
int main() {
INT(n, q);
RangeUpdateQuery<int> RUQ(n, (1u << 31) - 1);
while (q--) {
rep(q) {
INT(t);
if (t == 0) {
INT(l, r, x);
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/DSL/DSL_2_E.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
int main() {
INT(n, q);
RangeAddQuery<int> RAQ(n);
while (q--) {
rep(q) {
INT(t);
if (t == 0) {
INT(l, r, x);
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/DSL/DSL_2_F.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
int main() {
INT(n, q);
RangeUpdateQueryRangeMinimumQuery<int, (1u << 31) - 1> RUQRMQ(n);
while (q--) {
rep(q) {
INT(t);
if (t == 0) {
INT(l, r, x);
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/DSL/DSL_2_G.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
int main() {
INT(n, q);
RangeAddQueryRangeSumQuery<ll> RAQRSQ(n);
while (q--) {
rep(q) {
INT(t);
if (t == 0) {
INT(l, r, x);
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/DSL/DSL_2_H.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
int main() {
INT(n, q);
RangeAddQueryRangeMinimumQuery<int> RAQRMQ(n, 0);
while (q--) {
rep(q) {
INT(t);
if (t == 0) {
INT(l, r, x);
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/DSL/DSL_2_I.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
int main() {
INT(n, q);
RangeUpdateQueryRangeSumQuery<int> RUQRSQ(n);
while (q--) {
rep(q) {
INT(t);
if (t == 0) {
INT(l, r, x);
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/GRL/GRL_3_C.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main() {
scc.read(e, 0, false, true);
scc.build();
INT(q);
while (q--) {
rep(q) {
INT(a, b);
print(scc[a] == scc[b]);
}
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/GRL/GRL_5_C_1.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int main() {
}
g.build();
INT(q);
while (q--) {
rep(q) {
INT(a, b);
print(g.lca(a, b));
}
Expand Down
2 changes: 1 addition & 1 deletion test/aoj/GRL/GRL_5_C_2.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int main() {
}
g.build();
INT(q);
while (q--) {
rep(q) {
INT(a, b);
print(g.lca(a, b));
}
Expand Down
2 changes: 1 addition & 1 deletion test/yosupo/data_strucuture/associative_array.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ int main() {
int q;
sc >> q;
HashMap<ll, ll> mp;
while (q--) {
rep(q) {
int t;
sc >> t;
if (t) {
Expand Down
2 changes: 1 addition & 1 deletion test/yosupo/data_strucuture/point_add_range_sum1.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int main() {
vl a(n);
sc >> a;
RangeSumQuery<ll> RSQ(a);
while (q--) {
rep(q) {
int t, l, r;
sc >> t >> l >> r;
if (t == 0)
Expand Down
2 changes: 1 addition & 1 deletion test/yosupo/data_strucuture/point_add_range_sum2.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ int main() {
INT(a);
bit.add(i, a);
}
while (q--) {
rep(q) {
INT(t, l, r);
if (t)
print(bit.sum(l, r));
Expand Down
2 changes: 1 addition & 1 deletion test/yosupo/data_strucuture/point_add_range_sum3.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int main() {
vi a(n);
sc >> a;
rep(i, n) seg.set(i, a[i]);
while (q--) {
rep(q) {
INT(t, l, r);
if (t)
print(seg.query(l, r));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ int main() {
vector<T> a(n);
sc >> a;
SegmentTree<Monoid::Composite<mint>> seg(a);
while (q--) {
rep(q) {
INT(t, a, b, c);
if (t == 0)
seg.set(a, T{b, c});
Expand Down
2 changes: 1 addition & 1 deletion test/yosupo/data_strucuture/predecessor_problem.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main() {
FastSet st(n);
STR(s);
rep(i, n) if (s[i] == '1') st.insert(i);
while (q--) {
rep(q) {
INT(t, k);
if (t == 0) {
if (!st.contains(k)) st.insert(k);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int main() {
auto f = [](S a, S b) { return S(a.first * b.first, a.second * b.first + b.second); };
SlidingWindowAggregation swag(f, S(1, 0));
INT(q);
while (q--) {
rep(q) {
LL(t);
if (t == 0) {
mint a, b;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ int main() {
vector<mint> a(n);
sc >> a;
LazySegmentTree<Monoid::AffineSum<mint>> seg(a);
while (q--) {
rep(q) {
INT(t);
if (t == 0) {
INT(l, r, b, c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main() {
vl a(n);
sc >> a;
SegmentTreeBeats<ll> seg(a);
while (q--) {
rep(q) {
int t;
sc >> t;
if (t == 0) {
Expand Down
2 changes: 1 addition & 1 deletion test/yosupo/data_strucuture/range_kth_smallest.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main() {
vi a(n);
sc >> a;
CompressedWaveletMatrix<int, 18> w(a);
while (q--) {
rep(q) {
int l, r, k;
sc >> l >> r >> k;
print(w.kth_smallest(l, r, k));
Expand Down
2 changes: 1 addition & 1 deletion test/yosupo/data_strucuture/set_xor_min.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ int main() {
BinaryTrie<int> bt;
int q;
sc >> q;
while (q--) {
rep(q) {
int t, x;
sc >> t >> x;
if (t == 0) {
Expand Down
2 changes: 1 addition & 1 deletion test/yosupo/data_strucuture/static_range_sum.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main() {
vl a(n);
sc >> a;
DisjointSparseTable<Monoid::Sum<ll>> st(a);
while (q--) {
rep(q) {
INT(l, r);
print(st.prod(l, r));
}
Expand Down
2 changes: 1 addition & 1 deletion test/yosupo/data_strucuture/staticrmq.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main() {
vi a(n);
sc >> a;
SparseTable<Monoid::Min<int>> st(a);
while (q--) {
rep(q) {
INT(l, r);
print(st.prod(l, r));
}
Expand Down
2 changes: 1 addition & 1 deletion test/yosupo/data_strucuture/staticrmq2.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main() {
vi a(n);
sc >> a;
DisjointSparseTable<Monoid::Min<int>> st(a);
while (q--) {
rep(q) {
INT(l, r);
print(st.prod(l, r));
}
Expand Down
Loading

0 comments on commit 96a09f1

Please sign in to comment.