This documentation is automatically generated by competitive-verifier/competitive-verifier
// competitive-verifier: PROBLEM https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_2_D
#include "ds/dual_segtree.hpp"
int main() {
int n, q;
scanf("%d%d", &n, &q);
auto op = [](unsigned a, unsigned b) { return ~b ? b : a; };
dual_segment_tree st(n, unsigned(1 << 31) - 1, monoid(CONST(~0u), op), op);
while (q--) {
int cmd;
scanf("%d", &cmd);
if (cmd == 0) {
int s, t, x;
scanf("%d%d%d", &s, &t, &x);
st.apply(s, t + 1, x);
} else {
int i;
scanf("%d", &i);
printf("%u\n", st.get(i));
}
}
}
#line 1 "test/ds/dual_segtree.test.cpp"
// competitive-verifier: PROBLEM https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_2_D
#line 2 "prelude.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vc = vector<char>;
#define rep2(i, m, n) for (auto i = (m); i < (n); i++)
#define rep(i, n) rep2(i, 0, n)
#define repr2(i, m, n) for (auto i = (n); i-- > (m);)
#define repr(i, n) repr2(i, 0, n)
#define all(x) begin(x), end(x)
auto ndvec(int n, auto e) { return vector(n, e); }
auto ndvec(int n, auto ...e) { return vector(n, ndvec(e...)); }
auto comp_key(auto&& f) { return [&](auto&& a, auto&& b) { return f(a) < f(b); }; }
auto& max(const auto& a, const auto& b) { return a < b ? b : a; }
auto& min(const auto& a, const auto& b) { return b < a ? b : a; }
#if __cpp_lib_ranges
namespace R = std::ranges;
namespace V = std::views;
#endif
#line 3 "algebra.hpp"
#define CONST(val) [=] { return val; }
#define WRAP_FN(func) \
[](auto&&... args) { return func(forward<decltype(args)>(args)...); }
template <class Unit, class Op>
struct monoid : private Unit, private Op {
using type = decltype(declval<Unit>()());
monoid(Unit unit, Op op) : Unit(unit), Op(op) {}
type unit() const { return Unit::operator()(); }
type op(type a, type b) const { return Op::operator()(a, b); }
};
template <class Unit, class Op, class Inv>
struct group : monoid<Unit, Op>, private Inv {
using type = typename monoid<Unit, Op>::type;
group(Unit unit, Op op, Inv inv) : monoid<Unit, Op>(unit, op), Inv(inv) {}
type inv(type a) const { return Inv::operator()(a); }
};
template <class T>
struct addition {
using type = T;
type unit() const { return 0; }
type op(type a, type b) const { return a + b; }
type inv(type a) const { return -a; }
};
template <class T>
struct maximum {
using type = T;
type unit() const { return numeric_limits<T>::min(); }
type op(type a, type b) const { return a > b ? a : b; }
};
template <class T>
struct minimum {
using type = T;
type unit() const { return numeric_limits<T>::max(); }
type op(type a, type b) const { return a > b ? b : a; }
};
template <class T, T nul = -1>
struct assign {
using type = T;
type unit() const { return nul; }
type op(type a, type b) const { return b == nul ? a : b; }
};
#line 3 "bit/ctz.hpp"
#pragma GCC target("bmi")
template <class T>
int ctz(T x) {
if (!x) return sizeof(T) * 8;
if constexpr (sizeof(T) <= sizeof(unsigned)) {
return __builtin_ctz((unsigned)x);
} else if constexpr (sizeof(T) <= sizeof(unsigned long long)) {
return __builtin_ctzll((unsigned long long)x);
} else if constexpr (sizeof(T) <= sizeof(unsigned long long) * 2) {
unsigned long long y = x;
return y ? ctz(y)
: sizeof(y) * 8 + ctz((unsigned long long)(x >> sizeof(y) * 8));
}
}
#line 3 "bit/clz.hpp"
#pragma GCC target("lzcnt")
template <class T>
int clz(T x) {
if (!x) return sizeof(T) * 8;
if constexpr (sizeof(T) <= sizeof(unsigned)) {
return __builtin_clz((unsigned)x);
} else if constexpr (sizeof(T) <= sizeof(unsigned long long)) {
return __builtin_clzll((unsigned long long)x);
} else if constexpr (sizeof(T) <= sizeof(unsigned long long) * 2) {
int l = clz((unsigned long long)(x >> sizeof(unsigned long long) * 8));
return l != sizeof(unsigned long long) * 8 ? l : l + clz((unsigned long long)x);
}
}
#line 4 "bit/ilog2.hpp"
template <class T>
__attribute__((pure)) int ilog2(T x) { assert(x != 0); return sizeof(T) * 8 - 1 - clz(x); }
template <class T>
__attribute__((pure)) int ilog2_ceil(T x) { return x == 0 || x == 1 ? 0 : ilog2(x - 1) + 1; }
template <class T, enable_if_t<is_signed_v<T>>* = nullptr>
__attribute__((pure)) T bit_floor(T x) { return T(1) << ilog2(x); }
template <class T, enable_if_t<is_signed_v<T>>* = nullptr>
__attribute__((pure)) T bit_ceil(T x) { return T(1) << ilog2_ceil(x); }
#line 5 "ds/dual_segtree.hpp"
template <class T, class A, class F>
class dual_segment_tree {
public:
using value_type = T;
using actor_type = typename A::type;
dual_segment_tree(vector<value_type> v, A a = A(), F f = F())
: a(a), f(f), data(move(v)), lazy(data.size(), a.unit()) {}
template <class Iter>
dual_segment_tree(Iter first, Iter last, A a = A(), F f = F())
: dual_segment_tree({first, last}, a, f) {}
dual_segment_tree(int n = 0, T e = T(), A a = A(), F f = F())
: a(a), f(f), data(n, e), lazy(n, a.unit()) {}
int size() const { return data.size(); }
value_type get(int i) {
flush(i + size());
return data[i];
}
void apply(int l, int r, actor_type x) {
if (x == a.unit()) return;
flush(trunc(l + size()));
flush(trunc(r + size()) - 1);
for (int L = l + size(), R = r + size(); L < R; L >>= 1, R >>= 1) {
if (L & 1) apply(L++, x);
if (R & 1) apply(--R, x);
}
}
void mul(int i, value_type v) {
exec(i, [=](value_type& e) { e = e.op(e, v); });
}
void set(int i, value_type v) {
exec(i, [=](value_type& e) { e = v; });
}
template <class G>
void exec(int i, G f) {
flush(trunc(i + size()));
f(data[i]);
}
private:
A a;
F f;
vector<value_type> data;
vector<actor_type> lazy;
static int trunc(int a) { return a >> ctz(a); }
void apply(int i, actor_type x) {
if (i < size())
lazy[i] = a.op(lazy[i], x);
else
data[i - size()] = f(data[i - size()], x);
}
void push(int i) {
if (lazy[i] != a.unit()) {
apply(i << 1, lazy[i]);
apply(i << 1 | 1, lazy[i]);
lazy[i] = a.unit();
}
}
void flush(int i) {
if (i)
for (int s = ilog2(i); s > 0; s--) push(i >> s);
}
};
#line 4 "test/ds/dual_segtree.test.cpp"
int main() {
int n, q;
scanf("%d%d", &n, &q);
auto op = [](unsigned a, unsigned b) { return ~b ? b : a; };
dual_segment_tree st(n, unsigned(1 << 31) - 1, monoid(CONST(~0u), op), op);
while (q--) {
int cmd;
scanf("%d", &cmd);
if (cmd == 0) {
int s, t, x;
scanf("%d%d%d", &s, &t, &x);
st.apply(s, t + 1, x);
} else {
int i;
scanf("%d", &i);
printf("%u\n", st.get(i));
}
}
}
Env | Name | Status | Elapsed | Memory |
---|---|---|---|---|
g++-12 | 00_sample_00.in |
![]() |
12 ms | 8 MB |
g++-12 | 00_sample_01.in |
![]() |
12 ms | 8 MB |
g++-12 | 01_rand_00.in |
![]() |
12 ms | 8 MB |
g++-12 | 01_rand_01.in |
![]() |
12 ms | 8 MB |
g++-12 | 01_rand_02.in |
![]() |
11 ms | 8 MB |
g++-12 | 01_rand_03.in |
![]() |
12 ms | 8 MB |
g++-12 | 01_rand_04.in |
![]() |
12 ms | 8 MB |
g++-12 | 01_rand_05.in |
![]() |
15 ms | 8 MB |
g++-12 | 02_corner_00.in |
![]() |
12 ms | 8 MB |
g++-12 | 02_corner_01.in |
![]() |
12 ms | 8 MB |
g++-12 | 03_large_00.in |
![]() |
17 ms | 8 MB |
g++-12 | 03_large_01.in |
![]() |
18 ms | 8 MB |
g++-12 | 03_large_02.in |
![]() |
17 ms | 8 MB |
g++-12 | 03_large_03.in |
![]() |
17 ms | 8 MB |
g++-12 | 04_maximum_00.in |
![]() |
58 ms | 9 MB |
g++-12 | 04_maximum_01.in |
![]() |
63 ms | 9 MB |
g++-12 | 04_maximum_02.in |
![]() |
68 ms | 9 MB |
g++-12 | 04_maximum_03.in |
![]() |
60 ms | 9 MB |
g++-12 | 05_critical_00.in |
![]() |
52 ms | 9 MB |
g++-12 | 05_critical_01.in |
![]() |
47 ms | 9 MB |
g++-12 | 05_critical_02.in |
![]() |
55 ms | 9 MB |
g++-12 | 05_critical_03.in |
![]() |
54 ms | 9 MB |