Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 31 additions & 92 deletions .verify-helper/timestamps.remote.json

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions library/data_structures/README.md

This file was deleted.

33 changes: 0 additions & 33 deletions library/data_structures/uncommon/disjoint_rmq_inc.hpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
struct BIT {
vector<ll> s;
BIT(int n): s(n) {}
#include "bit_uncommon/vector_constructor.hpp"
#include "bit_uncommon/init.hpp"
void update(int i, ll d) {
for (; i < sz(s); i |= i + 1) s[i] += d;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "lazy_seg_tree_midpoint.hpp"
#include "seg_tree_midpoint.hpp"
ll op(ll vl, ll vr) { return vl + vr; }
struct seg_tree {
int n;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "../lazy_seg_tree_midpoint.hpp"
#include "../seg_tree_midpoint.hpp"
struct merge_sort_tree {
int n;
vector<vi> tree;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "linear_rmq.hpp"
#include "../../data_structures_[l,r]/linear_rmq.hpp"
//! https://codeforces.com/blog/entry/78898
//! @code
//! auto [p, root, ch] = perm_tree(a);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#pragma once
//! @time O(n + q log n)
//! @space O(n)
struct bit_inc {
// NOLINTNEXTLINE(readability-identifier-naming)
struct BIT {
vector<ll> s;
bit_inc(int n): s(n) {}
BIT(int n): s(n) {}
#include "../data_structures_[l,r)/bit_uncommon/init.hpp"
void update(int i, ll d) {
for (; i < sz(s); i |= i + 1) s[i] += d;
}
Expand All @@ -15,5 +17,5 @@ struct bit_inc {
ll query(int l, int r) { // [l, r]
return query(r) - query(l - 1);
}
#include "bit_uncommon/walk.hpp"
#include "../data_structures_[l,r)/bit_uncommon/walk.hpp"
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ template<class T, class F> struct disjoint_rmq {
}
}
}
T query(int l, int r) { // [l, r)
assert(l < r);
if (r - l == 1) return dp[0][l];
int lg = __lg(l ^ (r - 1));
return op(dp[lg][l], dp[lg][r - 1]);
T query(int l, int r) { // [l, r]
if (l == r) return dp[0][l];
int lg = __lg(l ^ r);
return op(dp[lg][l], dp[lg][r]);
}
};
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#pragma once
#include "lazy_seg_tree_inc_midpoint.hpp"
ll op_inc(ll vl, ll vr) { return vl + vr; }
struct seg_tree_inc {
#include "seg_tree_midpoint.hpp"
ll op(ll vl, ll vr) { return vl + vr; }
struct seg_tree {
int n;
vector<ll> tree, lazy;
seg_tree_inc(int n): n(n), tree(2 * n), lazy(n) {}
seg_tree_inc(const vi& a):
n(sz(a)), tree(2 * n), lazy(n) {
seg_tree(int n): n(n), tree(2 * n), lazy(n) {}
seg_tree(const vi& a): n(sz(a)), tree(2 * n), lazy(n) {
int pw2 = bit_ceil(size(a));
rep(i, 0, n) tree[(i + pw2) % n + n] = a[i];
for (int i = n - 1; i >= 1; i--)
tree[i] = op_inc(tree[2 * i], tree[2 * i + 1]);
tree[i] = op(tree[2 * i], tree[2 * i + 1]);
}
void apply(ll change, int tl, int tr, int v) {
tree[v] += (tr - tl + 1) * change;
Expand All @@ -31,21 +30,21 @@ struct seg_tree_inc {
if (r < tl || tr < l) return;
if (l <= tl && tr <= r)
return apply(change, tl, tr, v);
int tm = split_inc(tl, tr);
int tm = split(tl, tr);
push(tl, tm, tr, v);
update_impl(l, r, change, tl, tm, 2 * v);
update_impl(l, r, change, tm + 1, tr, 2 * v + 1);
tree[v] = op_inc(tree[2 * v], tree[2 * v + 1]);
tree[v] = op(tree[2 * v], tree[2 * v + 1]);
}
ll query(int l, int r) { // [l, r]
return query_impl(l, r, 0, n - 1, 1);
}
ll query_impl(int l, int r, int tl, int tr, int v) {
if (r < tl || tr < l) return 0;
if (l <= tl && tr <= r) return tree[v];
int tm = split_inc(tl, tr);
int tm = split(tl, tr);
push(tl, tm, tr, v);
return op_inc(query_impl(l, r, tl, tm, 2 * v),
return op(query_impl(l, r, tl, tm, 2 * v),
query_impl(l, r, tm + 1, tr, 2 * v + 1));
}
};
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#pragma once
//! @code
//! rmq_inc rmq1(a, ranges::min);
//! rmq_inc rmq2(a, [&](auto& x, auto& y) {
//! RMQ rmq1(a, ranges::min);
//! RMQ rmq2(a, [&](auto& x, auto& y) {
//! return min(x, y);
//! });
//! vector<rmq_inc<int, function<int(int, int)>>>
//! vector<RMQ<int, function<int(int, int)>>>
//! rmqs(3, {{}, NULL});
//! rmqs[1] = {a, ranges::min};
//! @endcode
//! @time O(nlogn + q)
//! @space O(nlogn)
template<class T, class F> struct rmq_inc {
// NOLINTNEXTLINE(readability-identifier-naming)
template<class T, class F> struct RMQ {
vector<vector<T>> dp;
F op;
rmq_inc(const vector<T>& a, F op): dp(1, a), op(op) {
RMQ(const vector<T>& a, F op): dp(1, a), op(op) {
for (int i = 0; (2 << i) <= sz(a); i++) {
dp.emplace_back(sz(a) - (2 << i) + 1);
ranges::transform(dp[i], dp[i] | views::drop(1 << i),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
//! https://codeforces.com/blog/entry/118682
//! @code
//! {
//! tree_inc st(n, pii{}, [&](pii& l, pii& r) {
//! tree st(n, pii{}, [&](pii& l, pii& r) {
//! return min(l, r);
//! });
//! }
//! tree_inc st(n, int{}, ranges::min);
//! tree st(n, int{}, ranges::min);
//! rep(i, 0, n) st.update(i, a[i]);
//! @endcode
//! @time O(n + q log n)
Expand All @@ -15,11 +15,11 @@ int nxt(int& l, int r) {
int lg = __lg(min(l & -l, r - l + 1));
return exchange(l, l + (1 << lg)) >> lg;
}
template<class T, class F> struct tree_inc {
template<class T, class F> struct tree {
int n;
F op;
vector<T> s;
tree_inc(int n, T, F op): n(n), op(op), s(2 * n) {}
tree(int n, T, F op): n(n), op(op), s(2 * n) {}
void update(int i, T val) {
for (s[i += n] = val; i /= 2;)
s[i] = op(s[2 * i], s[2 * i + 1]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once
//! https://codeforces.com/blog/entry/112755
//! @code
//! int tm = split_inc(tl, tr);
//! int tm = split(tl, tr);
//! // [tl,tr] splits into [tl,tm] and [tm+1,tr]
//! @endcode
int split_inc(int tl, int tr) {
int split(int tl, int tr) {
int pw2 = 1 << __lg(tr - tl + 1);
return min(tl + pw2 - 1, tr - pw2 / 2);
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#pragma once
#include "../../../kactl/content/data-structures/UnionFind.h"
#include "dsu.hpp"
//! Given l1,l2,len; joins (l1,l2), (l1+1,l2+1),
//! ..., (l1+len-1,l2+len-1)
//! `f` is called at most n-1 times
//! @time O(n*log(n)*\alpha(n) + q)
//! @space O(n log n)
struct rp_dsu {
vector<UF> ufs;
rp_dsu(int n): ufs(bit_width(unsigned(n)), UF(n)) {}
vector<DSU> dsus;
rp_dsu(int n): dsus(bit_width(unsigned(n)), DSU(n)) {}
void join(int l1, int l2, int len, const auto& f) {
if (len == 0) return;
int lg = __lg(len);
Expand All @@ -17,13 +17,13 @@ struct rp_dsu {
}
void join_impl(int lvl, int u, int v, const auto& f) {
if (lvl == 0) {
u = ufs[0].find(u);
v = ufs[0].find(v);
if (!ufs[0].join(v, u)) return;
int w = ufs[0].find(u);
u = dsus[0].f(u);
v = dsus[0].f(v);
if (!dsus[0].join(v, u)) return;
int w = dsus[0].f(u);
return f(w, u ^ v ^ w);
}
if (!ufs[lvl].join(u, v)) return;
if (!dsus[lvl].join(u, v)) return;
join_impl(lvl - 1, u, v, f);
join_impl(lvl - 1, u + (1 << (lvl - 1)),
v + (1 << (lvl - 1)), f);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#pragma once
#include "../../../kactl/content/data-structures/UnionFind.h"
#include "dsu.hpp"
//! Given triplets (l1,l2,len); joins (l1,l2),
//! (l1+1,l2+1), ..., (l1+len-1,l2+len-1)
//! @time O((n + q) * \alpha(n))
//! @space O(n + q)
UF get_rp_dsu(const vector<array<int, 3>>& rests, int n) {
DSU get_rp_dsu(const vector<array<int, 3>>& rests, int n) {
vector<vector<pii>> rests_by_len(n + 1);
for (auto [l1, l2, len] : rests)
rests_by_len[len].emplace_back(l1, l2);
UF uf(n);
DSU dsu(n);
for (int len = n; len > 0; len--)
for (auto [l1, l2] : rests_by_len[len])
if (uf.join(l1, l2))
if (dsu.join(l1, l2))
rests_by_len[len - 1].emplace_back(l1 + 1, l2 + 1);
return uf;
return dsu;
}
8 changes: 4 additions & 4 deletions library/graphs/bcc_callback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! @code
//! {
//! vector<vi> adj(n);
//! UF uf(n);
//! DSU dsu(n);
//! vector<bool> seen(n);
//! bcc(adj, [&](const vi& nodes) {
//! int count_edges = 0;
Expand All @@ -18,13 +18,13 @@
//! // nodes[0] <=> nodes[1] is a bridge
//! return;
//! }
//! for (int u : nodes) uf.join(u, nodes[0]);
//! for (int u : nodes) dsu.join(u, nodes[0]);
//! });
//! vector<basic_string<int>> bridge_tree(n);
//! rep (i, 0, n)
//! for (int u : adj[i])
//! if (!uf.sameSet(i, u))
//! bridge_tree[uf.find(i)] += uf.find(u);
//! if (dsu.f(i) != dsu.f(u))
//! bridge_tree[dsu.f(i)] += dsu.f(u);
//! }
//!
//! vector<basic_string<int>> adj(n);
Expand Down
2 changes: 1 addition & 1 deletion library/graphs/mst.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "../data_structures/dsu/dsu.hpp"
#include "../dsu/dsu.hpp"
//! @code
//! auto [mst_cost, ids] = mst(w_eds, n);
//! @endcode
Expand Down
2 changes: 1 addition & 1 deletion library/strings/longest_common_subsequence/lcs_queries.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "../../data_structures/bit.hpp"
#include "../../data_structures_[l,r)/bit.hpp"
#include "lcs_dp.hpp"
//! @code
//! string s,t;
Expand Down
2 changes: 1 addition & 1 deletion library/strings/manacher/longest_palindrome_query.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "../../data_structures/rmq.hpp"
#include "../../data_structures_[l,r)/rmq.hpp"
#include "manacher.hpp"
//! queries for longest palindromic substring of a given
//! substring
Expand Down
2 changes: 1 addition & 1 deletion library/strings/suffix_array/suffix_array_query.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "suffix_array.hpp"
#include "../../data_structures/rmq.hpp"
#include "../../data_structures_[l,r)/rmq.hpp"
#include "find/match.hpp"
//! @code
//! string s;
Expand Down
2 changes: 1 addition & 1 deletion library/trees/lca_rmq.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "../monotonic_stack/monotonic_stack.hpp"
#include "../data_structures/rmq.hpp"
#include "../data_structures_[l,r)/rmq.hpp"
//! https://github.com/kth-competitive-programming/kactl/blob/main/content/graph/LCA.h
//! @code
//! vector<basic_string<int>> adj(n);
Expand Down
2 changes: 1 addition & 1 deletion library/trees/uncommon/contour_range_query.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "../../data_structures/bit.hpp"
#include "../../data_structures_[l,r)/bit.hpp"
#include "../edge_cd.hpp"
#include "sum_adjacent.hpp"
//! https://judge.yosupo.jp/problem/vertex_add_range_contour_sum_on_tree
Expand Down
2 changes: 1 addition & 1 deletion library/trees/uncommon/contour_range_update.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "../../data_structures/bit_uncommon/rupq.hpp"
#include "../../data_structures_[l,r)/bit_uncommon/rupq.hpp"
#include "../edge_cd.hpp"
#include "sum_adjacent.hpp"
//! https://judge.yosupo.jp/problem/vertex_get_range_contour_add_on_tree
Expand Down
10 changes: 6 additions & 4 deletions tests/.config/.cppcheck_suppression_list
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ syntaxError:../library/math/prime_sieve/mobius.hpp:6
syntaxError:../library/trees/lca_rmq/iterate_subtree.hpp:6
knownConditionTrueFalse:../library/strings/suffix_array/suffix_array.hpp:62
knownConditionTrueFalse:../library/strings/suffix_array/suffix_array_short.hpp:29
knownConditionTrueFalse:../library/data_structures/dsu/kruskal_tree.hpp:15
knownConditionTrueFalse:../library/data_structures/dsu/dsu.hpp:11
knownConditionTrueFalse:../library/dsu/kruskal_tree.hpp:15
knownConditionTrueFalse:../library/dsu/dsu.hpp:11
constVariable:../kactl/content/numerical/NumberTheoreticTransform.h:30
constVariable:../kactl/content/graph/CompressTree.h:20
constVariableReference:../kactl/content/graph/CompressTree.h:20
Expand All @@ -52,11 +52,13 @@ constVariableReference:library_checker_aizu_tests/handmade_tests/dsu_size.test.c
constVariableReference:../library/trees/centroid_decomp_uncommon/count_paths_per_length.hpp:34
constVariablePointer:../kactl/content/numerical/FastFourierTransform.h:39
cstyleCast:../kactl/content/numerical/FastFourierTransform.h:39
derefInvalidIterator:../library/data_structures/uncommon/linear_rmq.hpp:27
derefInvalidIterator:../library/data_structures_[l,r]/linear_rmq.hpp:27
derefInvalidIterator:library_checker_aizu_tests/handmade_tests/n_choose_k.test.cpp:13
unreadVariable:library_checker_aizu_tests/handmade_tests/permutation_tree_small.test.cpp:12
uninitvar:library_checker_aizu_tests/handmade_tests/seg_tree_find_small.test.cpp:41
unusedFunction:../kactl/content/data-structures/UnionFind.h:14
unusedFunction:../kactl/content/number-theory/ModPow.h:13
unusedFunction:../kactl/stress-tests/utilities/genTree.h:49
containerOutOfBounds:../library/data_structures/uncommon/permutation_tree.hpp:85
containerOutOfBounds:../library/data_structures_[l,r)/uncommon/permutation_tree.hpp:85
ctuOneDefinitionRuleViolation:../library/data_structures_[l,r)/bit.hpp:5
ctuOneDefinitionRuleViolation:../library/data_structures_[l,r)/lazy_seg_tree.hpp:4
Loading
Loading