Skip to content

Commit 4f80c04

Browse files
committed
thread safe lazy_segtree with global mutex
1 parent 92234ea commit 4f80c04

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

atcoder/lazysegtree.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
#include <algorithm>
55
#include <cassert>
66
#include <iostream>
7+
#include <mutex>
78
#include <vector>
89

910
#include "atcoder/internal_bit"
1011

1112
namespace atcoder {
13+
std::mutex mtx_all_apply, mtx_push;
1214

1315
template <class S,
1416
S (*op)(S, S),
@@ -174,10 +176,12 @@ struct lazy_segtree {
174176

175177
void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
176178
void all_apply(int k, F f) const {
179+
std::lock_guard<std::mutex> guard(mtx_all_apply);
177180
d[k] = mapping(f, d[k]);
178181
if (k < size) lz[k] = composition(f, lz[k]);
179182
}
180183
void push(int k) const {
184+
std::lock_guard<std::mutex> guard(mtx_push);
181185
all_apply(2 * k, lz[k]);
182186
all_apply(2 * k + 1, lz[k]);
183187
lz[k] = id();

0 commit comments

Comments
 (0)