Skip to content

Commit

Permalink
fix bit01 bug; add erasable_mono_pairheap; add lazymap/lazyumap/lazys…
Browse files Browse the repository at this point in the history
…et/lazyuset;
  • Loading branch information
old-yan committed Oct 26, 2024
1 parent 6bd6da1 commit 77a75dd
Show file tree
Hide file tree
Showing 55 changed files with 2,682 additions and 111 deletions.
5 changes: 3 additions & 2 deletions DS/AVL.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
5. [P4070 [SDOI2016] 生成魔咒](https://www.luogu.com.cn/problem/P4070)
6. [P5494 【模板】线段树分裂](https://www.luogu.com.cn/problem/P5494)
7. [P6136 【模板】普通平衡树(数据加强版)](https://www.luogu.com.cn/problem/P6136)
8. [数据结构](https://ac.nowcoder.com/acm/problem/276699)
9. [Dynamic Sequence Range Affine Range Sum](https://judge.yosupo.jp/problem/dynamic_sequence_range_affine_range_sum)(https://github.com/yosupo06/library-checker-problems/issues/242)
8. [寿命修改](https://ac.nowcoder.com/acm/problem/275139)
9. [数据结构](https://ac.nowcoder.com/acm/problem/276699)
10. [Dynamic Sequence Range Affine Range Sum](https://judge.yosupo.jp/problem/dynamic_sequence_range_affine_range_sum)(https://github.com/yosupo06/library-checker-problems/issues/242)


### 二、模板功能
Expand Down
3 changes: 2 additions & 1 deletion DS/AdjDiff.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
6. [P4655 [CEOI2017] Building Bridges](https://www.luogu.com.cn/problem/P4655)
7. [P10843 【MX-J2-T4】Turtle and Cycles](https://www.luogu.com.cn/problem/P10843)
8. [fsl 的背包](https://ac.nowcoder.com/acm/problem/263978)
9. [Static Range Sum](https://judge.yosupo.jp/problem/static_range_sum)(https://github.com/yosupo06/library-checker-problems/issues/398)
9. [k - 路径(hard vension)](https://ac.nowcoder.com/acm/problem/279411)
10. [Static Range Sum](https://judge.yosupo.jp/problem/static_range_sum)(https://github.com/yosupo06/library-checker-problems/issues/398)


### 二、模板功能
Expand Down
2 changes: 1 addition & 1 deletion DS/BIT01.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace OY {
return res;
}
size_type query(size_type i) const { return m_bits[i >> MASK_WIDTH] >> (i & (MASK_SIZE - 1)) & 1; }
size_type query(size_type left, size_type right) const { return presum(right) - presum(left); }
size_type query(size_type left, size_type right) const { return presum(right) - presum(left - 1); }
size_type kth(size_type k) const {
size_type cursor = -1;
for (size_type d = m_icap >> 1; d; d >>= 1)
Expand Down
1 change: 1 addition & 0 deletions DS/BIT01.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

1. [Hotaru's problem](https://acm.hdu.edu.cn/showproblem.php?pid=5371)
2. [P4070 [SDOI2016] 生成魔咒](https://www.luogu.com.cn/problem/P4070)
3. [寿命修改](https://ac.nowcoder.com/acm/problem/275139)

### 二、模板功能

Expand Down
3 changes: 2 additions & 1 deletion DS/CompressedTree.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

​ 练习题目:

1. [U311262 求区间后继](https://www.luogu.com.cn/problem/U311262)
1. [P1801 黑匣子](https://www.luogu.com.cn/problem/P1801)
2. [U311262 求区间后继](https://www.luogu.com.cn/problem/U311262)

### 二、模板功能

Expand Down
102 changes: 102 additions & 0 deletions DS/ErasableMonoPairHeap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
最后修改:
20241020
测试环境:
gcc11.2,c++11
clang22.0,C++11
msvc14.2,C++14
*/
#ifndef __OY_ERASABLEMONOPAIRHEAP__
#define __OY_ERASABLEMONOPAIRHEAP__

#include "MonoPairHeap.h"

namespace OY {
namespace EMONOPH {
using size_type = MONOPH::size_type;
template <typename Tp>
struct AddCommutativeGroup {
using value_type = Tp;
static Tp identity() { return Tp{}; }
static Tp op(const Tp &x, const Tp &y) { return x + y; }
static Tp inverse(const Tp &x) { return -x; }
};
template <typename Tp>
struct BitxorCommutativeGroup {
using value_type = Tp;
static Tp identity() { return Tp{}; }
static Tp op(const Tp &x, const Tp &y) { return x ^ y; }
static Tp inverse(const Tp &x) { return x; }
};
template <typename CommutativeGroup>
struct Trait {
using group = CommutativeGroup;
using value_type = typename group::value_type;
using sum_type = typename MONOPH::Has_Sum_Type<group, value_type>::type;
static constexpr bool has_op = MONOPH::Has_Op<group, sum_type>::value;
};
template <typename CommutativeGroup, bool HasOp = Trait<CommutativeGroup>::has_op>
struct HeapBase : Trait<CommutativeGroup> {
typename Trait<CommutativeGroup>::sum_type m_prod;
HeapBase() : m_prod(CommutativeGroup::identity()) {}
};
template <typename CommutativeGroup>
struct HeapBase<CommutativeGroup, false> : Trait<CommutativeGroup> {};
template <typename CommutativeGroup, typename Compare = std::less<typename CommutativeGroup::value_type>, template <typename> typename BufferType = VectorBufferWithCollect>
class Heap : HeapBase<CommutativeGroup> {
public:
using typename HeapBase<CommutativeGroup>::group;
using typename HeapBase<CommutativeGroup>::value_type;
using typename HeapBase<CommutativeGroup>::sum_type;
using HeapBase<CommutativeGroup>::has_op;
using heap_type = Heap<CommutativeGroup, Compare, BufferType>;
using inner_type = MONOPH::Heap<MONOPH::NoOp<value_type>, Compare, BufferType>;
using buffer_type = typename inner_type::buffer_type;
static void _reserve(size_type capacity) { inner_type::_reserve(capacity); }
private:
mutable inner_type m_data, m_lazy;
size_type m_sz;
public:
Heap() : m_sz() {}
void clear() {
m_data.clear(), m_lazy.clear(), m_sz = 0;
if constexpr (has_op) this->m_prod = group::identity();
}
size_type size() const { return m_sz; }
bool empty() const { return !m_sz; }
void push(const value_type &x) {
m_data.push(x), m_sz++;
if constexpr (has_op) this->m_prod = group::op(this->m_prod, x);
}
void erase(const value_type &x) {
m_lazy.push(x), m_sz--;
if constexpr (has_op) this->m_prod = group::op(this->m_prod, group::inverse(x));
}
void pop() {
while (!m_lazy.empty() && !Compare()(m_lazy.top(), m_data.top())) m_data.pop(), m_lazy.pop();
if constexpr (has_op) this->m_prod = group::op(this->m_prod, group::inverse(m_data.top()));
m_data.pop(), m_sz--;
}
const value_type &top() const {
while (!m_lazy.empty() && !Compare()(m_lazy.top(), m_data.top())) m_data.pop(), m_lazy.pop();
return m_data.top();
}
void join(heap_type &rhs) {
if (!rhs.empty()) {
m_data.join(rhs.m_data), m_lazy.join(rhs.m_lazy), rhs.m_sz = 0;
if constexpr (has_op) this->m_prod = group::op(this->m_prod, rhs.m_prod), rhs.m_prod = group::identity();
}
}
void join(heap_type &&rhs) { join(rhs); }
const sum_type &query_all() const { return this->m_prod; }
};
}
template <typename Tp, typename Compare = std::less<Tp>, template <typename> typename BufferType = VectorBufferWithCollect>
using ErasableMonoPairHeap = EMONOPH::Heap<MONOPH::NoOp<Tp>, Compare, BufferType>;
template <typename Tp, typename Compare = std::less<Tp>>
using VectorErasableMonoSumPairHeap = EMONOPH::Heap<EMONOPH::AddCommutativeGroup<Tp>, Compare>;
template <typename Tp, typename Compare = std::less<Tp>>
using VectorErasableMonoBitXorPairHeap = EMONOPH::Heap<EMONOPH::BitxorCommutativeGroup<Tp>, Compare>;
}

#endif
52 changes: 52 additions & 0 deletions DS/ErasableMonoPairHeap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
### 一、模板类别

​ 数据结构:可删除元素的配对堆。

​ 练习题目:

1. [3321. 计算子数组的 x-sum II](https://leetcode.cn/problems/find-x-sum-of-all-k-long-subarrays-ii)


### 二、模板功能

​ 本模板为支持维护信息的堆。同时,借助懒删除技术,实现了堆中元素的删除。

​ 与 `MonoPairHeap` 不同的是,本模板要求传入的代数结构为交换群,需要存在逆元。只有通过差分才可以实时维护堆的信息。

​ 需要注意的是, `erase` 函数需要保证,每次传入的元素必须仍在堆中,未被删除。

​ 在接口上,并无特殊之处。


### 三、模板示例

```c++
#include "DS/ErasableMonoPairHeap.h"
#include "IO/FastIO.h"

void test() {
OY::VectorErasableMonoSumPairHeap<int> S;
S.push(100);
S.push(400);
S.push(200);
S.push(300);
S.push(500);
S.erase(200);
S.erase(400);
cout << "size = " << S.size() << endl;
S.pop();
cout << "sum = " << S.query_all() << endl;
}

int main() {
test();
}
```

```
#输出如下
size = 3
sum = 400
```

9 changes: 5 additions & 4 deletions DS/GlobalHashBIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
​ 练习题目:

1. [940. 不同的子序列 II](https://leetcode.cn/problems/distinct-subsequences-ii)
2. [P3369 【模板】普通平衡树](https://www.luogu.com.cn/problem/P3369)
3. [P3372 【模板】线段树 1](https://www.luogu.com.cn/problem/P3372)
4. [P6136 【模板】普通平衡树(数据加强版)](https://www.luogu.com.cn/problem/P6136)
5. [U187320 【模板】树状数组 3](https://www.luogu.com.cn/problem/U187320)
2. [P1801 黑匣子](https://www.luogu.com.cn/problem/P1801)
3. [P3369 【模板】普通平衡树](https://www.luogu.com.cn/problem/P3369)
4. [P3372 【模板】线段树 1](https://www.luogu.com.cn/problem/P3372)
5. [P6136 【模板】普通平衡树(数据加强版)](https://www.luogu.com.cn/problem/P6136)
6. [U187320 【模板】树状数组 3](https://www.luogu.com.cn/problem/U187320)



Expand Down
2 changes: 2 additions & 0 deletions DS/MaskRMQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
2. [P1886 滑动窗口 /【模板】单调队列](https://www.luogu.com.cn/problem/P1886)
3. [P3793 由乃救爷爷](https://www.luogu.com.cn/problem/P3793)
4. [P3865 【模板】ST 表](https://www.luogu.com.cn/problem/P3865)
5. [k - 路径(hard vension)](https://ac.nowcoder.com/acm/problem/279411)
6. [小红的树上路径查询(hard)](https://ac.nowcoder.com/acm/problem/281352)


### 二、模板功能
Expand Down
13 changes: 7 additions & 6 deletions DS/MergeSortTree.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
​ 练习题目:

1. [Minimum Sum](https://acm.hdu.edu.cn/showproblem.php?pid=3473)
2. [P3834 【模板】可持久化线段树 2](https://www.luogu.com.cn/problem/P3834)
3. [P4094 [HEOI2016/TJOI2016] 字符串](https://www.luogu.com.cn/problem/P4094)
4. [P10814 【模板】离线二维数点](https://www.luogu.com.cn/problem/P10814)
5. [U311262 求区间后继](https://www.luogu.com.cn/problem/U311262)
6. [fsl 的背包](https://ac.nowcoder.com/acm/problem/263978)
7. [Range Kth Smallest](https://judge.yosupo.jp/problem/range_kth_smallest)(https://github.com/yosupo06/library-checker-problems/issues/310)
2. [P1801 黑匣子](https://www.luogu.com.cn/problem/P1801)
3. [P3834 【模板】可持久化线段树 2](https://www.luogu.com.cn/problem/P3834)
4. [P4094 [HEOI2016/TJOI2016] 字符串](https://www.luogu.com.cn/problem/P4094)
5. [P10814 【模板】离线二维数点](https://www.luogu.com.cn/problem/P10814)
6. [U311262 求区间后继](https://www.luogu.com.cn/problem/U311262)
7. [fsl 的背包](https://ac.nowcoder.com/acm/problem/263978)
8. [Range Kth Smallest](https://judge.yosupo.jp/problem/range_kth_smallest)(https://github.com/yosupo06/library-checker-problems/issues/310)


### 二、模板功能
Expand Down
23 changes: 12 additions & 11 deletions DS/MonoAVL.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@

1. [3321. 计算子数组的 x-sum II](https://leetcode.cn/problems/find-x-sum-of-all-k-long-subarrays-ii)
2. [P1503 鬼子进村](https://www.luogu.com.cn/problem/P1503)
3. [P1886 滑动窗口 /【模板】单调队列](https://www.luogu.com.cn/problem/P1886)
4. [P3369 【模板】普通平衡树](https://www.luogu.com.cn/problem/P3369)
5. [P3391 【模板】文艺平衡树](https://www.luogu.com.cn/problem/P3391)
6. [P4036 [JSOI2008] 火星人](https://www.luogu.com.cn/problem/P4036)
7. [P4774 [NOI2018] 屠龙勇士](https://www.luogu.com.cn/problem/P4774)
8. [P6136 【模板】普通平衡树(数据加强版)](https://www.luogu.com.cn/problem/P6136)
9. [U361730 【模板】完全体·堆](https://www.luogu.com.cn/problem/U361730)
10. [翻转排序](https://ac.nowcoder.com/acm/problem/275173)
11. [旅途的终点](https://ac.nowcoder.com/acm/problem/275989)
12. [正义从不打背身](https://ac.nowcoder.com/acm/problem/277862)
13. [Range Reverse Range Sum](https://judge.yosupo.jp/problem/range_reverse_range_sum)(https://github.com/yosupo06/library-checker-problems/issues/538)
3. [P1801 黑匣子](https://www.luogu.com.cn/problem/P1801)
4. [P1886 滑动窗口 /【模板】单调队列](https://www.luogu.com.cn/problem/P1886)
5. [P3369 【模板】普通平衡树](https://www.luogu.com.cn/problem/P3369)
6. [P3391 【模板】文艺平衡树](https://www.luogu.com.cn/problem/P3391)
7. [P4036 [JSOI2008] 火星人](https://www.luogu.com.cn/problem/P4036)
8. [P4774 [NOI2018] 屠龙勇士](https://www.luogu.com.cn/problem/P4774)
9. [P6136 【模板】普通平衡树(数据加强版)](https://www.luogu.com.cn/problem/P6136)
10. [U361730 【模板】完全体·堆](https://www.luogu.com.cn/problem/U361730)
11. [翻转排序](https://ac.nowcoder.com/acm/problem/275173)
12. [旅途的终点](https://ac.nowcoder.com/acm/problem/275989)
13. [正义从不打背身](https://ac.nowcoder.com/acm/problem/277862)
14. [Range Reverse Range Sum](https://judge.yosupo.jp/problem/range_reverse_range_sum)(https://github.com/yosupo06/library-checker-problems/issues/538)


### 二、模板功能
Expand Down
2 changes: 0 additions & 2 deletions DS/MonoPairHeap.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ namespace OY {
static_assert(buffer_type::is_vector_buffer, "Only In Vector Mode");
buffer_type::s_buf.reserve(capacity);
}

private:
size_type m_rt{};
static node *_ptr(size_type cur) { return buffer_type::data() + cur; }
Expand Down Expand Up @@ -140,7 +139,6 @@ namespace OY {
_pushup(p), _pushup(_ptr(a));
return b ? _merge(_merge(x, a), _merges(b)) : _merge(x, a);
}

public:
Heap() { static Initializer _init; }
Heap(const heap_type &rhs) = delete;
Expand Down
8 changes: 5 additions & 3 deletions DS/MonoPairHeap.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

​ 练习题目:

1. [P3377 【模板】左偏树(可并堆)](https://www.luogu.com.cn/problem/P3377)
2. [P3378 【模板】堆](https://www.luogu.com.cn/problem/P3378)
3. [U361730 【模板】完全体·堆](https://www.luogu.com.cn/problem/U361730)
1. [P1801 黑匣子](https://www.luogu.com.cn/problem/P1801)
2. [P3377 【模板】左偏树(可并堆)](https://www.luogu.com.cn/problem/P3377)
3. [P3378 【模板】堆](https://www.luogu.com.cn/problem/P3378)
4. [U361730 【模板】完全体·堆](https://www.luogu.com.cn/problem/U361730)
5. [旅途的终点](https://ac.nowcoder.com/acm/problem/275989)


### 二、模板功能
Expand Down
23 changes: 12 additions & 11 deletions DS/MonoSplay.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@

1. [3321. 计算子数组的 x-sum II](https://leetcode.cn/problems/find-x-sum-of-all-k-long-subarrays-ii)
2. [P1503 鬼子进村](https://www.luogu.com.cn/problem/P1503)
3. [P1886 滑动窗口 /【模板】单调队列](https://www.luogu.com.cn/problem/P1886)
4. [P3369 【模板】普通平衡树](https://www.luogu.com.cn/problem/P3369)
5. [P3391 【模板】文艺平衡树](https://www.luogu.com.cn/problem/P3391)
6. [P4036 [JSOI2008] 火星人](https://www.luogu.com.cn/problem/P4036)
7. [P4774 [NOI2018] 屠龙勇士](https://www.luogu.com.cn/problem/P4774)
8. [P6136 【模板】普通平衡树(数据加强版)](https://www.luogu.com.cn/problem/P6136)
9. [U361730 【模板】完全体·堆](https://www.luogu.com.cn/problem/U361730)
10. [翻转排序](https://ac.nowcoder.com/acm/problem/275173)
11. [旅途的终点](https://ac.nowcoder.com/acm/problem/275989)
12. [正义从不打背身](https://ac.nowcoder.com/acm/problem/277862)
13. [Range Reverse Range Sum](https://judge.yosupo.jp/problem/range_reverse_range_sum)(https://github.com/yosupo06/library-checker-problems/issues/538)
3. [P1801 黑匣子](https://www.luogu.com.cn/problem/P1801)
4. [P1886 滑动窗口 /【模板】单调队列](https://www.luogu.com.cn/problem/P1886)
5. [P3369 【模板】普通平衡树](https://www.luogu.com.cn/problem/P3369)
6. [P3391 【模板】文艺平衡树](https://www.luogu.com.cn/problem/P3391)
7. [P4036 [JSOI2008] 火星人](https://www.luogu.com.cn/problem/P4036)
8. [P4774 [NOI2018] 屠龙勇士](https://www.luogu.com.cn/problem/P4774)
9. [P6136 【模板】普通平衡树(数据加强版)](https://www.luogu.com.cn/problem/P6136)
10. [U361730 【模板】完全体·堆](https://www.luogu.com.cn/problem/U361730)
11. [翻转排序](https://ac.nowcoder.com/acm/problem/275173)
12. [旅途的终点](https://ac.nowcoder.com/acm/problem/275989)
13. [正义从不打背身](https://ac.nowcoder.com/acm/problem/277862)
14. [Range Reverse Range Sum](https://judge.yosupo.jp/problem/range_reverse_range_sum)(https://github.com/yosupo06/library-checker-problems/issues/538)


### 二、模板功能
Expand Down
8 changes: 4 additions & 4 deletions DS/MultiDimSegTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ namespace OY {
}
};
}
template <typename SizeType, typename BaseMaxTable, size_t DIM, bool HasModify>
using MonoMaxMDSeg = MDSEG::Tree<SizeType, typename BaseMaxTable::group, BaseMaxTable, DIM, HasModify>;
template <typename SizeType, typename BaseMinTable, size_t DIM, bool HasModify>
using MonoMinMDSeg = MDSEG::Tree<SizeType, typename BaseMinTable::group, BaseMinTable, DIM, HasModify>;
template <typename SizeType, typename BaseMaxTable, size_t DIM, bool HasModify, typename CommutativeMonoid = typename BaseMaxTable::group>
using MonoMaxMDSeg = MDSEG::Tree<SizeType, CommutativeMonoid, BaseMaxTable, DIM, HasModify>;
template <typename SizeType, typename BaseMinTable, size_t DIM, bool HasModify, typename CommutativeMonoid = typename BaseMinTable::group>
using MonoMinMDSeg = MDSEG::Tree<SizeType, CommutativeMonoid, BaseMinTable, DIM, HasModify>;
template <typename SizeType, typename Tp, size_t DIM>
using MonoSumMDST = MDSEG::Tree<SizeType, MDSEG::BaseCommutativeMonoid<Tp, 0, std::plus<Tp>>, MDSEG::AdjTable<Tp>, DIM, false>;
template <typename SizeType, typename Tp, size_t DIM>
Expand Down
Loading

0 comments on commit 77a75dd

Please sign in to comment.