結果
問題 | No.2653 [Cherry 6th Tune] Re: start! (Make it Zero!) |
ユーザー | ebi_fly |
提出日時 | 2024-02-23 23:26:10 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 14,174 bytes |
コンパイル時間 | 3,544 ms |
コンパイル使用メモリ | 269,740 KB |
実行使用メモリ | 29,188 KB |
最終ジャッジ日時 | 2024-09-29 08:58:36 |
合計ジャッジ時間 | 18,337 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | WA | - |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | WA | - |
testcase_62 | WA | - |
testcase_63 | WA | - |
testcase_64 | WA | - |
testcase_65 | WA | - |
testcase_66 | WA | - |
testcase_67 | WA | - |
testcase_68 | WA | - |
testcase_69 | WA | - |
testcase_70 | WA | - |
testcase_71 | WA | - |
ソースコード
#line 1 "template/template.hpp" #include <bits/stdc++.h> #define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++) #define rrep(i, a, n) for (int i = ((int)(n)-1); i >= (int)(a); i--) #define Rep(i, a, n) for (i64 i = (i64)(a); i < (i64)(n); i++) #define RRep(i, a, n) for (i64 i = ((i64)(n)-i64(1)); i >= (i64)(a); i--) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #line 2 "template/debug_template.hpp" #line 4 "template/debug_template.hpp" namespace ebi { #ifdef LOCAL #define debug(...) \ std::cerr << "LINE: " << __LINE__ << " [" << #__VA_ARGS__ << "]:", \ debug_out(__VA_ARGS__) #else #define debug(...) #endif void debug_out() { std::cerr << std::endl; } template <typename Head, typename... Tail> void debug_out(Head h, Tail... t) { std::cerr << " " << h; if (sizeof...(t) > 0) std::cerr << " :"; debug_out(t...); } } // namespace ebi #line 2 "template/int_alias.hpp" #line 4 "template/int_alias.hpp" namespace ebi { using ld = long double; using std::size_t; using i8 = std::int8_t; using u8 = std::uint8_t; using i16 = std::int16_t; using u16 = std::uint16_t; using i32 = std::int32_t; using u32 = std::uint32_t; using i64 = std::int64_t; using u64 = std::uint64_t; using i128 = __int128_t; using u128 = __uint128_t; } // namespace ebi #line 2 "template/io.hpp" #line 5 "template/io.hpp" #include <optional> #line 7 "template/io.hpp" namespace ebi { template <typename T1, typename T2> std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &pa) { return os << pa.first << " " << pa.second; } template <typename T1, typename T2> std::istream &operator>>(std::istream &os, std::pair<T1, T2> &pa) { return os >> pa.first >> pa.second; } template <typename T> std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec) { for (std::size_t i = 0; i < vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : " "); return os; } template <typename T> std::istream &operator>>(std::istream &os, std::vector<T> &vec) { for (T &e : vec) std::cin >> e; return os; } template <typename T> std::ostream &operator<<(std::ostream &os, const std::optional<T> &opt) { if (opt) { os << opt.value(); } else { os << "invalid value"; } return os; } void fast_io() { std::cout << std::fixed << std::setprecision(15); std::cin.tie(nullptr); std::ios::sync_with_stdio(false); } } // namespace ebi #line 2 "template/utility.hpp" #line 5 "template/utility.hpp" #line 2 "graph/template.hpp" #line 4 "graph/template.hpp" namespace ebi { template <class T> struct Edge { int to; T cost; Edge(int _to, T _cost = 1) : to(_to), cost(_cost) {} }; template <class T> struct Graph : std::vector<std::vector<Edge<T>>> { using std::vector<std::vector<Edge<T>>>::vector; void add_edge(int u, int v, T w, bool directed = false) { (*this)[u].emplace_back(v, w); if (directed) return; (*this)[v].emplace_back(u, w); } }; struct graph : std::vector<std::vector<int>> { using std::vector<std::vector<int>>::vector; void add_edge(int u, int v, bool directed = false) { (*this)[u].emplace_back(v); if (directed) return; (*this)[v].emplace_back(u); } }; } // namespace ebi #line 8 "template/utility.hpp" namespace ebi { template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> T safe_ceil(T a, T b) { if (a % b == 0) return a / b; else if (a >= 0) return (a / b) + 1; else return -((-a) / b); } template <class T> T safe_floor(T a, T b) { if (a % b == 0) return a / b; else if (a >= 0) return a / b; else return -((-a) / b) - 1; } constexpr i64 LNF = std::numeric_limits<i64>::max() / 4; constexpr int INF = std::numeric_limits<int>::max() / 2; const std::vector<int> dy = {1, 0, -1, 0, 1, 1, -1, -1}; const std::vector<int> dx = {0, 1, 0, -1, 1, -1, 1, -1}; } // namespace ebi #line 2 "data_structure/lazy_segtree.hpp" /* reference: https://atcoder.github.io/ac-library/master/document_ja/lazysegtree.html */ #include <bit> #line 11 "data_structure/lazy_segtree.hpp" #include <ranges> #line 13 "data_structure/lazy_segtree.hpp" namespace ebi { template <class S, S (*op)(S, S), S (*e)(), class F, S (*mapping)(F, S), F (*composition)(F, F), F (*id)()> struct lazy_segtree { private: void update(int i) { data[i] = op(data[2 * i], data[2 * i + 1]); } void all_apply(int k, F f) { data[k] = mapping(f, data[k]); if (k < sz) lazy[k] = composition(f, lazy[k]); } void push(int i) { all_apply(2 * i, lazy[i]); all_apply(2 * i + 1, lazy[i]); lazy[i] = id(); } public: lazy_segtree(int n_) : lazy_segtree(std::vector<S>(n_, e())) {} lazy_segtree(const std::vector<S> &a) : n(a.size()), sz(std::bit_ceil(a.size())), lg2(std::countr_zero(std::uint32_t(sz))) { data = std::vector<S>(2 * sz, e()); lazy = std::vector<F>(sz, id()); for (int i : std::views::iota(0, n)) { data[sz + i] = a[i]; } for (int i : std::views::iota(1, sz) | std::views::reverse) { update(i); } } void set(int p, S x) { assert(0 <= p && p < n); p += sz; for (int i = lg2; i >= 1; i--) push(p >> i); data[p] = x; for (int i = 1; i <= lg2; i++) update(p >> i); } S get(int p) { assert(0 <= p && p < n); p += sz; for (int i = lg2; i >= 1; i--) push(p >> i); return data[p]; } S prod(int l, int r) { assert(0 <= l && l <= r && r <= n); if (l == r) return e(); l += sz; r += sz; for (int i = lg2; i >= 1; i--) { if (((l >> i) << i) != l) push(l >> i); if (((r >> i) << i) != r) push((r - 1) >> i); } S sml = e(), smr = e(); while (l < r) { if (l & 1) sml = op(sml, data[l++]); if (r & 1) smr = op(data[--r], smr); l >>= 1; r >>= 1; } return op(sml, smr); } S all_prod() const { return data[1]; } void apply(int p, F f) { assert(0 <= p && p < n); p += sz; for (int i = lg2; i >= 1; i--) push(p >> i); data[p] = mapping(f, data[p]); for (int i = 1; i <= lg2; i++) update(p >> i); } void apply(int l, int r, F f) { assert(0 <= l && l <= r && r <= n); l += sz; r += sz; for (int i = lg2; i >= 1; i--) { if (((l >> i) << i) != l) push(l >> i); if (((r >> i) << i) != r) push((r - 1) >> i); } { int memo_l = l, memo_r = r; while (l < r) { if (l & 1) all_apply(l++, f); if (r & 1) all_apply(--r, f); l >>= 1; r >>= 1; } l = memo_l; r = memo_r; } for (int i = 1; i <= lg2; i++) { if (((l >> i) << i) != l) update(l >> i); if (((r >> i) << i) != r) update((r - 1) >> i); } } template <class G> int max_right(int l, G g) { assert(0 <= l && l <= n); assert(g(e())); if (l == n) return n; l += sz; for (int i = lg2; i >= 1; i--) push(l >> i); S sm = e(); do { while (l % 2 == 0) l >>= 1; if (!g(op(sm, data[l]))) { while (l < sz) { push(l); l = l << 1; if (g(op(sm, data[l]))) { sm = op(sm, data[l]); l++; } } return l - sz; } sm = op(sm, data[l]); l++; } while ((l & -l) != l); return n; } template <class G> int min_left(int r, G g) { assert(0 <= r && r <= n); assert(g(e())); if (r == 0) return 0; r += sz; for (int i = lg2; i >= 1; i--) push((r - 1) >> i); S sm = e(); do { r--; while (r > 1 && r % 2) r >>= 1; if (!g(op(data[r], sm))) { while (r < sz) { push(r); r = (r << 1) + 1; if (g(op(data[r], sm))) { sm = op(data[r], sm); r--; } } return r + 1 - sz; } sm = op(data[r], sm); } while ((r & -r) != r); return 0; } private: int n, sz, lg2; std::vector<S> data; std::vector<F> lazy; }; } // namespace ebi #line 3 "a.cpp" #line 2 "modint/modint.hpp" #line 5 "modint/modint.hpp" #line 2 "modint/base.hpp" #include <concepts> #line 6 "modint/base.hpp" namespace ebi { template <class T> concept Modint = requires(T a, T b) { a + b; a - b; a * b; a / b; a.inv(); a.val(); a.pow(std::declval<long long>()); T::mod(); }; template <Modint mint> std::istream &operator>>(std::istream &os, mint &a) { long long x; os >> x; a = x; return os; } template <Modint mint> std::ostream &operator<<(std::ostream &os, const mint &a) { return os << a.val(); } } // namespace ebi #line 7 "modint/modint.hpp" namespace ebi { template <int m> struct static_modint { private: using modint = static_modint; public: static constexpr int mod() { return m; } static constexpr modint raw(int v) { modint x; x._v = v; return x; } constexpr static_modint() : _v(0) {} constexpr static_modint(long long v) { v %= (long long)umod(); if (v < 0) v += (long long)umod(); _v = (unsigned int)v; } constexpr unsigned int val() const { return _v; } constexpr unsigned int value() const { return val(); } constexpr modint &operator++() { _v++; if (_v == umod()) _v = 0; return *this; } constexpr modint &operator--() { if (_v == 0) _v = umod(); _v--; return *this; } constexpr modint operator++(int) { modint res = *this; ++*this; return res; } constexpr modint operator--(int) { modint res = *this; --*this; return res; } constexpr modint &operator+=(const modint &rhs) { _v += rhs._v; if (_v >= umod()) _v -= umod(); return *this; } constexpr modint &operator-=(const modint &rhs) { _v -= rhs._v; if (_v >= umod()) _v += umod(); return *this; } constexpr modint &operator*=(const modint &rhs) { unsigned long long x = _v; x *= rhs._v; _v = (unsigned int)(x % (unsigned long long)umod()); return *this; } constexpr modint &operator/=(const modint &rhs) { return *this = *this * rhs.inv(); } constexpr modint operator+() const { return *this; } constexpr modint operator-() const { return modint() - *this; } constexpr modint pow(long long n) const { assert(0 <= n); modint x = *this, res = 1; while (n) { if (n & 1) res *= x; x *= x; n >>= 1; } return res; } constexpr modint inv() const { assert(_v); return pow(umod() - 2); } friend modint operator+(const modint &lhs, const modint &rhs) { return modint(lhs) += rhs; } friend modint operator-(const modint &lhs, const modint &rhs) { return modint(lhs) -= rhs; } friend modint operator*(const modint &lhs, const modint &rhs) { return modint(lhs) *= rhs; } friend modint operator/(const modint &lhs, const modint &rhs) { return modint(lhs) /= rhs; } friend bool operator==(const modint &lhs, const modint &rhs) { return lhs.val() == rhs.val(); } friend bool operator!=(const modint &lhs, const modint &rhs) { return !(lhs == rhs); } private: unsigned int _v = 0; static constexpr unsigned int umod() { return m; } }; using modint998244353 = static_modint<998244353>; using modint1000000007 = static_modint<1000000007>; } // namespace ebi #line 5 "a.cpp" namespace ebi { using mint = modint998244353; mint op(mint a, mint b) { return a + b; } mint e() { return 0; } mint mapping(mint f, mint x) { return f * x; } mint composition(mint f, mint g) { return f * g; } mint id() { return 1; } void main_() { int n,m; std::cin >> n >> m; std::vector<i64> xs(n); std::cin >> xs; std::map<i64, mint> map1, map2; lazy_segtree<mint, op, e, mint, mapping, composition, id> seg1(n+1), seg2(n+1); seg1.set(0, 1); seg2.set(0, 1); int r = 0; i64 sum = 0; mint inv_n = mint(n).inv(); rep(i,0,n) { if(xs[i] == -1) { seg1.apply(0, r, m-1); seg2.apply(0, r, m-1); map1.clear(); map2.clear(); r = i + 1; } else { sum += xs[i]; sum %= m; } mint ret1 = seg1.prod(0, r); mint ret2 = seg2.prod(0, r); if(xs[i] != -1) { ret1 += map1[sum]; ret2 += map2[sum]; map1[sum] += ret1; map2[sum] += ret2 - ret1 * inv_n; } seg1.set(i+1, ret1); seg2.set(i+1, ret2 - ret1 * inv_n); } mint ans = seg2.get(n) * n; std::cout << ans << '\n'; } } // namespace ebi int main() { ebi::fast_io(); int t = 1; std::cin >> t; while (t--) { ebi::main_(); } return 0; }