結果
問題 | No.1222 -101 |
ユーザー | KoD |
提出日時 | 2020-09-04 22:41:02 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 513 ms / 2,000 ms |
コード長 | 16,928 bytes |
コンパイル時間 | 1,092 ms |
コンパイル使用メモリ | 88,208 KB |
実行使用メモリ | 18,252 KB |
最終ジャッジ日時 | 2024-11-26 20:31:38 |
合計ジャッジ時間 | 7,967 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,820 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 2 ms
6,816 KB |
testcase_05 | AC | 2 ms
6,816 KB |
testcase_06 | AC | 2 ms
6,816 KB |
testcase_07 | AC | 2 ms
6,816 KB |
testcase_08 | AC | 2 ms
6,816 KB |
testcase_09 | AC | 2 ms
6,820 KB |
testcase_10 | AC | 201 ms
11,872 KB |
testcase_11 | AC | 199 ms
11,772 KB |
testcase_12 | AC | 330 ms
15,028 KB |
testcase_13 | AC | 328 ms
14,908 KB |
testcase_14 | AC | 330 ms
15,004 KB |
testcase_15 | AC | 260 ms
13,488 KB |
testcase_16 | AC | 293 ms
14,172 KB |
testcase_17 | AC | 315 ms
14,664 KB |
testcase_18 | AC | 257 ms
13,368 KB |
testcase_19 | AC | 269 ms
13,696 KB |
testcase_20 | AC | 293 ms
14,340 KB |
testcase_21 | AC | 294 ms
14,208 KB |
testcase_22 | AC | 2 ms
6,816 KB |
testcase_23 | AC | 2 ms
6,816 KB |
testcase_24 | AC | 2 ms
6,816 KB |
testcase_25 | AC | 2 ms
6,820 KB |
testcase_26 | AC | 2 ms
6,816 KB |
testcase_27 | AC | 2 ms
6,816 KB |
testcase_28 | AC | 2 ms
6,816 KB |
testcase_29 | AC | 2 ms
6,816 KB |
testcase_30 | AC | 2 ms
6,816 KB |
testcase_31 | AC | 2 ms
6,816 KB |
testcase_32 | AC | 513 ms
18,252 KB |
testcase_33 | AC | 499 ms
18,212 KB |
testcase_34 | AC | 161 ms
11,776 KB |
testcase_35 | AC | 164 ms
11,840 KB |
testcase_36 | AC | 165 ms
11,924 KB |
testcase_37 | AC | 166 ms
11,788 KB |
testcase_38 | AC | 164 ms
11,996 KB |
ソースコード
#line 1 "main.cpp" /** * @title Template */ #include <iostream> #include <algorithm> #include <utility> #include <numeric> #include <vector> #include <array> #include <cassert> #line 2 "/Users/kodamankod/Desktop/Programming/Library/other/chmin_chmax.cpp" template <class T, class U> constexpr bool chmin(T &lhs, const U &rhs) { if (lhs > rhs) { lhs = rhs; return true; } return false; } template <class T, class U> constexpr bool chmax(T &lhs, const U &rhs) { if (lhs < rhs) { lhs = rhs; return true; } return false; } /** * @title Chmin/Chmax */ #line 2 "/Users/kodamankod/Desktop/Programming/Library/other/range.cpp" #line 4 "/Users/kodamankod/Desktop/Programming/Library/other/range.cpp" class range { public: class iterator { private: int64_t M_position; public: constexpr iterator(int64_t position) noexcept: M_position(position) { } constexpr void operator ++ () noexcept { ++M_position; } constexpr bool operator != (iterator other) const noexcept { return M_position != other.M_position; } constexpr int64_t operator * () const noexcept { return M_position; } }; class reverse_iterator { private: int64_t M_position; public: constexpr reverse_iterator(int64_t position) noexcept: M_position(position) { } constexpr void operator ++ () noexcept { --M_position; } constexpr bool operator != (reverse_iterator other) const noexcept { return M_position != other.M_position; } constexpr int64_t operator * () const noexcept { return M_position; } }; private: const iterator M_first, M_last; public: constexpr range(int64_t first, int64_t last) noexcept: M_first(first), M_last(std::max(first, last)) { } constexpr iterator begin() const noexcept { return M_first; } constexpr iterator end() const noexcept { return M_last; } constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(*M_last - 1); } constexpr reverse_iterator rend() const noexcept { return reverse_iterator(*M_first - 1); } }; /** * @title Range */ #line 2 "/Users/kodamankod/Desktop/Programming/Library/other/rev.cpp" #include <type_traits> #include <iterator> #line 6 "/Users/kodamankod/Desktop/Programming/Library/other/rev.cpp" template <class T> class rev_impl { public: using iterator = decltype(std::rbegin(std::declval<T>())); private: const iterator M_begin; const iterator M_end; public: constexpr rev_impl(T &&cont) noexcept: M_begin(std::rbegin(cont)), M_end(std::rend(cont)) { } constexpr iterator begin() const noexcept { return M_begin; } constexpr iterator end() const noexcept { return M_end; } }; template <class T> constexpr decltype(auto) rev(T &&cont) { return rev_impl<T>(std::forward<T>(cont)); } /** * @title Reverser */ #line 2 "/Users/kodamankod/Desktop/Programming/Library/algebraic/modular.cpp" #include <cstdint> #line 5 "/Users/kodamankod/Desktop/Programming/Library/algebraic/modular.cpp" template <class Modulus> class modular { public: using value_type = uint32_t; using cover_type = uint64_t; static constexpr value_type mod() { return Modulus::value(); } template <class T> static constexpr value_type normalize(T value_) noexcept { if (value_ < 0) { value_ = -value_; value_ %= mod(); if (value_ == 0) return 0; return mod() - value_; } return value_ % mod(); } private: value_type value; public: constexpr modular() noexcept : value(0) { } template <class T> explicit constexpr modular(T value_) noexcept : value(normalize(value_)) { } template <class T> explicit constexpr operator T() const noexcept { return static_cast<T>(value); } constexpr value_type get() const noexcept { return value; } constexpr value_type &extract() noexcept { return value; } constexpr modular operator - () const noexcept { return modular(mod() - value); } constexpr modular operator ~ () const noexcept { return inverse(*this); } constexpr modular operator + (const modular &rhs) const noexcept { return modular(*this) += rhs; } constexpr modular& operator += (const modular &rhs) noexcept { if ((value += rhs.value) >= mod()) value -= mod(); return *this; } constexpr modular operator - (const modular &rhs) const noexcept { return modular(*this) -= rhs; } constexpr modular& operator -= (const modular &rhs) noexcept { if ((value += mod() - rhs.value) >= mod()) value -= mod(); return *this; } constexpr modular operator * (const modular &rhs) const noexcept { return modular(*this) *= rhs; } constexpr modular& operator *= (const modular &rhs) noexcept { value = (cover_type) value * rhs.value % mod(); return *this; } constexpr modular operator / (const modular &rhs) const noexcept { return modular(*this) /= rhs; } constexpr modular& operator /= (const modular &rhs) noexcept { return (*this) *= inverse(rhs); } constexpr bool zero() const noexcept { return value == 0; } constexpr bool operator == (const modular &rhs) const noexcept { return value == rhs.value; } constexpr bool operator != (const modular &rhs) const noexcept { return value != rhs.value; } friend std::ostream& operator << (std::ostream &stream, const modular &rhs) { return stream << rhs.value; } friend constexpr modular inverse(modular val) noexcept { return power(val, mod() - 2); } friend constexpr modular power(modular val, cover_type exp) noexcept { modular res(1); for (; exp > 0; exp >>= 1, val *= val) if (exp & 1) res *= val; return res; } }; template <uint32_t Val> struct modulus_impl { static constexpr uint32_t value() noexcept { return Val; } }; template <uint32_t Val> using mint32_t = modular<modulus_impl<Val>>; struct runtime_mod { static uint32_t &value() noexcept { static uint32_t val = 0; return val; } }; using rmint32_t = modular<runtime_mod>; /** * @title Modint */ #line 2 "/Users/kodamankod/Desktop/Programming/Library/container/lazy_propagation_segment_tree.cpp" #line 2 "/Users/kodamankod/Desktop/Programming/Library/other/bit_operation.cpp" #include <cstddef> #line 5 "/Users/kodamankod/Desktop/Programming/Library/other/bit_operation.cpp" constexpr size_t bit_ppc(const uint64_t x) { return __builtin_popcountll(x); } constexpr size_t bit_ctzr(const uint64_t x) { return x == 0 ? 64 : __builtin_ctzll(x); } constexpr size_t bit_ctzl(const uint64_t x) { return x == 0 ? 64 : __builtin_clzll(x); } constexpr size_t bit_width(const uint64_t x) { return 64 - bit_ctzl(x); } constexpr uint64_t bit_msb(const uint64_t x) { return x == 0 ? 0 : uint64_t(1) << (bit_width(x) - 1); } constexpr uint64_t bit_lsb(const uint64_t x) { return x & (-x); } constexpr uint64_t bit_cover(const uint64_t x) { return x == 0 ? 0 : bit_msb(2 * x - 1); } constexpr uint64_t bit_rev(uint64_t x) { x = ((x >> 1) & 0x5555555555555555) | ((x & 0x5555555555555555) << 1); x = ((x >> 2) & 0x3333333333333333) | ((x & 0x3333333333333333) << 2); x = ((x >> 4) & 0x0F0F0F0F0F0F0F0F) | ((x & 0x0F0F0F0F0F0F0F0F) << 4); x = ((x >> 8) & 0x00FF00FF00FF00FF) | ((x & 0x00FF00FF00FF00FF) << 8); x = ((x >> 16) & 0x0000FFFF0000FFFF) | ((x & 0x0000FFFF0000FFFF) << 16); x = (x >> 32) | (x << 32); return x; } /** * @title Bit Operations */ #line 2 "/Users/kodamankod/Desktop/Programming/Library/other/monoid.cpp" #include <type_traits> #line 5 "/Users/kodamankod/Desktop/Programming/Library/other/monoid.cpp" #include <stdexcept> template <class T, class = void> class has_identity: public std::false_type { }; template <class T> class has_identity<T, typename std::conditional<false, decltype(T::identity()), void>::type>: public std::true_type { }; template <class T> constexpr typename std::enable_if<has_identity<T>::value, typename T::type>::type empty_exception() { return T::identity(); } template <class T> [[noreturn]] constexpr typename std::enable_if<!has_identity<T>::value, typename T::type>::type empty_exception() { throw std::runtime_error("type T has no identity"); } template <class T, bool HasIdentity> class fixed_monoid_impl: public T { public: static constexpr typename T::type convert(const typename T::type &value) { return value; } static constexpr typename T::type revert(const typename T::type &value) { return value; } }; template <class T> class fixed_monoid_impl<T, false>: private T { public: class type { public: typename T::type value; bool state; explicit constexpr type(): value(typename T::type { }), state(false) { } explicit constexpr type(const typename T::type &value): value(value), state(true) { } }; static constexpr type convert(const typename T::type &value) { return type(value); } static constexpr typename T::type revert(const type &value) { if (!value.state) throw std::runtime_error("attempted to revert identity to non-monoid"); return value.value; } static constexpr type identity() { return type(); } static constexpr type operation(const type &v1, const type &v2) { if (!v1.state) return v2; if (!v2.state) return v1; return type(T::operation(v1.value, v2.value)); } }; template <class T> using fixed_monoid = fixed_monoid_impl<T, has_identity<T>::value>; template <class T, bool HasIdentity> class fixed_combined_monoid_impl { public: using value_structure = typename T::value_structure; using operator_structure = fixed_monoid<typename T::operator_structure>; template <class... Args> static constexpr typename value_structure::type operation( const typename value_structure::type &val, const typename operator_structure::type &op, Args&&... args) { return T::operation(val, op, std::forward<Args>(args)...); } }; template <class T> class fixed_combined_monoid_impl<T, false> { public: using value_structure = typename T::value_structure; using operator_structure = fixed_monoid<typename T::operator_structure>; template <class... Args> static constexpr typename value_structure::type operation( const typename value_structure::type &val, const typename operator_structure::type &op, Args&&... args) { if (!op.state) return val; return T::operation(val, op.value, std::forward<Args>(args)...); } }; template <class T> using fixed_combined_monoid = fixed_combined_monoid_impl<T, has_identity<typename T::operator_structure>::value>; /** * @title Monoid Utility */ #line 5 "/Users/kodamankod/Desktop/Programming/Library/container/lazy_propagation_segment_tree.cpp" #line 10 "/Users/kodamankod/Desktop/Programming/Library/container/lazy_propagation_segment_tree.cpp" template <class CombinedMonoid> class lazy_propagation_segment_tree { public: using structure = CombinedMonoid; using value_monoid = typename CombinedMonoid::value_structure; using operator_monoid = typename CombinedMonoid::operator_structure; using value_type = typename CombinedMonoid::value_structure::type; using operator_type = typename CombinedMonoid::operator_structure::type; using size_type = size_t; private: using fixed_structure = fixed_combined_monoid<structure>; using fixed_operator_monoid = typename fixed_structure::operator_structure; using fixed_operator_type = typename fixed_operator_monoid::type; class node_type { public: value_type value; fixed_operator_type lazy; node_type( const value_type &value = value_monoid::identity(), const fixed_operator_type &lazy = fixed_operator_monoid::identity() ): value(value), lazy(lazy) { } }; static void S_apply(node_type &node, const fixed_operator_type &op, const size_type length) { node.value = fixed_structure::operation(node.value, op, length); node.lazy = fixed_operator_monoid::operation(node.lazy, op); } void M_propagate(const size_type index, const size_type length) { S_apply(M_tree[index << 1 | 0], M_tree[index].lazy, length); S_apply(M_tree[index << 1 | 1], M_tree[index].lazy, length); M_tree[index].lazy = fixed_operator_monoid::identity(); } void M_fix_change(const size_type index) { M_tree[index].value = value_monoid::operation(M_tree[index << 1 | 0].value, M_tree[index << 1 | 1].value); } void M_pushdown(const size_type index) { const size_type lsb = bit_ctzr(index); for (size_type story = bit_width(index); story != lsb; --story) { M_propagate(index >> story, 1 << (story - 1)); } } void M_pullup(size_type index) { index >>= bit_ctzr(index); while (index != 1) { index >>= 1; M_fix_change(index); } } std::vector<node_type> M_tree; public: lazy_propagation_segment_tree() = default; explicit lazy_propagation_segment_tree(const size_type size) { initialize(size); } template <class InputIterator> explicit lazy_propagation_segment_tree(InputIterator first, InputIterator last) { construct(first, last); } void initialize(const size_type size) { clear(); M_tree.assign(size << 1, node_type()); } template <class InputIterator> void construct(InputIterator first, InputIterator last) { clear(); const size_type size = std::distance(first, last); M_tree.reserve(size << 1); M_tree.assign(size, node_type()); for (; first != last; ++first) { M_tree.emplace_back(*first, fixed_operator_monoid::identity()); } for (size_type index = size - 1; index != 0; --index) { M_fix_change(index); } } value_type fold(size_type first, size_type last) { first += size(); last += size(); M_pushdown(first); M_pushdown(last); value_type fold_l = value_monoid::identity(); value_type fold_r = value_monoid::identity(); while (first != last) { if (first & 1) { fold_l = value_monoid::operation(fold_l, M_tree[first].value); ++first; } if (last & 1) { --last; fold_r = value_monoid::operation(M_tree[last].value, fold_r); } first >>= 1; last >>= 1; } return value_monoid::operation(fold_l, fold_r); } void operate(size_type first, size_type last, const operator_type &op_) { const auto op = fixed_operator_monoid::convert(op_); first += size(); last += size(); M_pushdown(first); M_pushdown(last); const size_type first_c = first; const size_type last_c = last; for (size_type story = 0; first != last; ++story) { if (first & 1) { S_apply(M_tree[first], op, 1 << story); ++first; } if (last & 1) { --last; S_apply(M_tree[last], op, 1 << story); } first >>= 1; last >>= 1; } M_pullup(first_c); M_pullup(last_c); } void assign(size_type index, const value_type &val) { index += size(); for (size_type story = bit_width(index); story != 0; --story) { M_propagate(index >> story, 1 << (story - 1)); } M_tree[index].value = val; M_tree[index].lazy = fixed_operator_monoid::identity(); while (index != 1) { index >>= 1; M_fix_change(index); } } void clear() { M_tree.clear(); M_tree.shrink_to_fit(); } size_type size() const { return M_tree.size() >> 1; } }; /** * @title Lazy Propagation Segment Tree */ #line 19 "main.cpp" using i32 = int32_t; using i64 = int64_t; using u32 = uint32_t; using u64 = uint64_t; constexpr i32 inf32 = (i32(1) << 30) - 1; constexpr i64 inf64 = (i64(1) << 62) - 1; using m32 = mint32_t<1000000007>; struct lst_monoid { struct value_structure { using type = m32; static type identity() { return m32(0); } static type operation(const type& v1, const type& v2) { return v1 + v2; } }; struct operator_structure { using type = m32; static type identity() { return m32(1); } static type operation(const type& v1, const type& v2) { return v1 * v2; } }; static typename value_structure::type operation( const typename value_structure::type &val, const typename operator_structure::type &op, const size_t length = 1) { return val * op; } }; int main() { i32 N, M; std::cin >> N >> M; std::vector<i32> usage(N + 1); i32 nonzero = 0; std::vector<std::vector<i32>> Qs(N + 1); for (auto i: range(0, M)) { i32 l, r, p; std::cin >> l >> r >> p; --l; if (p == 0) { Qs[r].push_back(l); } else { ++nonzero; ++usage[l]; --usage[r]; } } m32 ans(1); for (auto i: range(0, N)) { usage[i + 1] += usage[i]; if (usage[i] > 0) { ans *= m32(2); } } ans /= power(m32(2), nonzero); lazy_propagation_segment_tree<lst_monoid> dp(N + 1); dp.assign(0, m32(1)); for (auto i: range(1, N + 1)) { if (usage[i - 1] == 0) { dp.assign(i, dp.fold(0, i)); dp.operate(0, i, m32(2)); } for (auto l: Qs[i]) { dp.operate(0, l + 1, m32(0)); } } std::cout << ans * dp.fold(0, N + 1) << '\n'; return 0; }