This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub SSRS-cp/cp_library
#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_F" #include <bits/stdc++.h> using namespace std; const int INF = 2147483647; #include "../../../data_structure/sequence/lazy_segment_tree.hpp" int main(){ int n, q; cin >> n >> q; function<int(int, int)> op = [](int a, int b){ return min(a, b); }; function<int(int, int)> mp = [](int a, int b){ if (a == -1){ return b; } else { return a; } }; function<int(int, int)> comp = [](int a, int b){ if (b == -1){ return a; } else { return b; } }; lazy_segment_tree<int, int> ST(n, op, mp, comp, INF, -1); for (int i = 0; i < q; i++){ int c; cin >> c; if (c == 0){ int s, t, x; cin >> s >> t >> x; t++; ST.range_apply(s, t, x); } if (c == 1){ int s, t; cin >> s >> t; t++; cout << ST.range_fold(s, t) << endl; } } }
#line 1 "test/aoj/dsl/dsl_2_f.test.cpp" #define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_F" #include <bits/stdc++.h> using namespace std; const int INF = 2147483647; #line 2 "data_structure/sequence/lazy_segment_tree.hpp" /** * @brief 遅延セグメント木 */ template <typename T, typename F> struct lazy_segment_tree{ int N; vector<T> ST; vector<F> lazy; function<T(T, T)> op; function<T(F, T)> mp; function<F(F, F)> comp; T E; F id; lazy_segment_tree(int n, function<T(T, T)> op, function<T(F, T)> mp, function<F(F, F)> comp, T E, F id): op(op), mp(mp), comp(comp), E(E), id(id){ N = 1; while (N < n){ N *= 2; } ST = vector<T>(N * 2 - 1, E); for (int i = N - 2; i >= 0; i--){ ST[i] = op(ST[i * 2 + 1], ST[i * 2 + 2]); } lazy = vector<F>(N * 2 - 1, id); } lazy_segment_tree(vector<T> &A, function<T(T, T)> op, function<T(F, T)> mp, function<F(F, F)> comp, T E, F id): op(op), mp(mp), comp(comp), E(E), id(id){ int n = A.size(); N = 1; while (N < n){ N *= 2; } ST = vector<T>(N * 2 - 1, E); for (int i = 0; i < n; i++){ ST[N - 1 + i] = A[i]; } for (int i = N - 2; i >= 0; i--){ ST[i] = op(ST[i * 2 + 1], ST[i * 2 + 2]); } lazy = vector<F>(N * 2 - 1, id); } void push(int i){ if (i < N - 1){ lazy[i * 2 + 1] = comp(lazy[i * 2 + 1], lazy[i]); lazy[i * 2 + 2] = comp(lazy[i * 2 + 2], lazy[i]); } ST[i] = mp(lazy[i], ST[i]); lazy[i] = id; } void range_apply(int L, int R, F f, int i, int l, int r){ push(i); if (r <= L || R <= l){ return; } else if (L <= l && r <= R){ lazy[i] = f; push(i); } else { int m = (l + r) / 2; range_apply(L, R, f, i * 2 + 1, l, m); range_apply(L, R, f, i * 2 + 2, m, r); ST[i] = op(ST[i * 2 + 1], ST[i * 2 + 2]); } } void range_apply(int L, int R, F f){ range_apply(L, R, f, 0, 0, N); } T range_fold(int L, int R, int i, int l, int r){ push(i); if (r <= L || R <= l){ return E; } else if (L <= l && r <= R){ return ST[i]; } else { int m = (l + r) / 2; return op(range_fold(L, R, i * 2 + 1, l, m), range_fold(L, R, i * 2 + 2, m, r)); } } T range_fold(int L, int R){ return range_fold(L, R, 0, 0, N); } T all(){ push(0); return ST[0]; } }; #line 6 "test/aoj/dsl/dsl_2_f.test.cpp" int main(){ int n, q; cin >> n >> q; function<int(int, int)> op = [](int a, int b){ return min(a, b); }; function<int(int, int)> mp = [](int a, int b){ if (a == -1){ return b; } else { return a; } }; function<int(int, int)> comp = [](int a, int b){ if (b == -1){ return a; } else { return b; } }; lazy_segment_tree<int, int> ST(n, op, mp, comp, INF, -1); for (int i = 0; i < q; i++){ int c; cin >> c; if (c == 0){ int s, t, x; cin >> s >> t >> x; t++; ST.range_apply(s, t, x); } if (c == 1){ int s, t; cin >> s >> t; t++; cout << ST.range_fold(s, t) << endl; } } }