結果
問題 | No.3110 WIP Editorial |
ユーザー | 👑 Nachia |
提出日時 | 2024-04-01 22:27:05 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 580 ms / 4,000 ms |
コード長 | 6,139 bytes |
コンパイル時間 | 1,415 ms |
コンパイル使用メモリ | 111,640 KB |
実行使用メモリ | 82,168 KB |
最終ジャッジ日時 | 2024-09-30 22:34:19 |
合計ジャッジ時間 | 6,040 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 256 ms
21,888 KB |
testcase_02 | AC | 370 ms
41,216 KB |
testcase_03 | AC | 413 ms
43,008 KB |
testcase_04 | AC | 534 ms
78,908 KB |
testcase_05 | AC | 551 ms
81,276 KB |
testcase_06 | AC | 579 ms
82,128 KB |
testcase_07 | AC | 580 ms
82,108 KB |
testcase_08 | AC | 571 ms
82,168 KB |
ソースコード
#ifdef NACHIA #define _GLIBCXX_DEBUG #else #define NDEBUG #endif #include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <queue> #include <array> #include <cmath> #include <atcoder/modint> namespace nachia{ template< class S, class F, S op(S l, S r), F composition(F f, F x), S mapping(F f, S x) > struct LazySegtree { private: struct Node { S s; F f; bool propagated; }; int N; int logN; int xN; std::vector<Node> A; void mapf(Node& a, F f){ a.propagated = false; a.f = composition(f, a.f); a.s = mapping(f, a.s); } void mergev(int i){ if(i<N) A[i].s = op(A[i*2].s, A[i*2+1].s); } void spread(int i){ if(A[i].propagated || !(i < N)) return; mapf(A[i*2], A[i].f); mapf(A[i*2+1], A[i].f); A[i].f = A[0].f; A[i].propagated = true; } // bool cmp(S) template<class E> int minLeft2(int r, E cmp, int a = 0, int b = 0, int i = -1){ static S x; if(i == -1){ a=0; b=N; i=1; x = A[0].s; } if(r <= a) return a; if(b <= r){ S nx = op(A[i].s, x); if(cmp(nx)){ x = nx; return a; } } if(b-a == 1) return b; spread(i); int q = minLeft2(r, cmp, (a+b)/2, b, i*2+1); if(q > (a+b)/2) return q; return minLeft2(r, cmp, a, (a+b)/2, i*2); } // bool cmp(S) template<class E> int maxRight2(int l, E cmp, int a = 0, int b = 0, int i = -1){ static S x; if(i == -1){ a=0; b=N; i=1; x = A[0].s; } if(b <= l) return b; if(l <= a){ S nx = op(x, A[i].s); if(cmp(nx)){ x = nx; return b; } } if(b - a == 1) return a; spread(i); int q = maxRight2(l, cmp, a, (a+b)/2, i*2); if(q < (a+b)/2) return q; return maxRight2(l, cmp, (a+b)/2, b, i*2+1); } public: LazySegtree() : N(0), logN(-1), xN(0){} LazySegtree(int n, S e, F id){ N=1; logN=0; xN=n; while(N<n){ N *= 2; logN++; } A.assign(N*2, { e, id, true }); } LazySegtree(const std::vector<S>& a, S e, F id) : LazySegtree(a.size(), std::move(e), std::move(id)){ for(std::size_t i=0; i<a.size(); i++) A[i+N].s = a[i]; for(int i=N-1; i>=1; i--) mergev(i); } void set(int p, S x){ p += N; for(int d=logN; d; d--) spread(p >> d); A[p].s = x; for(int d=1; d<=logN; d++) mergev(p >> d); } S get(int p){ p += N; for(int d=logN; d; d--) spread(p >> d); return A[p].s; } void apply(int p, F f){ set(p, mapping(f, get(p))); } void apply(int l, int r, F f){ if(!(l < r)) return; if(l == 0 && r == N){ mapf(A[1], f); return; } l += N; r += N; for(int d=logN; d; d--){ if((l >> d) << d != l) spread(l >> d); if((r >> d) << d != r) spread(r >> d); } int lp = l, rp = r; while(l < r){ if(l&1){ mapf(A[l++], f); } l /= 2; if(r&1){ mapf(A[--r], f); } r /= 2; } for(int d=1 ; d<=logN; d++){ if((lp >> d) << d != lp) mergev(lp >> d); if((rp >> d) << d != rp) mergev(rp >> d); } } S prod(int l, int r){ if(!(l < r)) return A[0].s; l += N; r += N; for(int d=logN; d; d--){ if((l >> d) << d != l) spread(l >> d); if((r >> d) << d != r) spread(r >> d); } S q1 = A[0].s, q2 = A[0].s; while(l < r){ if(l&1){ q1 = op(q1, A[l++].s); } l /= 2; if(r&1){ q2 = op(A[--r].s, q2); } r /= 2; } return op(q1, q2); } S allProd() const { return A[1].s; } // bool cmp(S) template<class E> int minLeft(int r, E cmp){ return minLeft2(r, cmp); } // bool cmp(S) template<class E> int maxRight(int l, E cmp){ int x = maxRight2(l, cmp); return x > xN ? xN : x; } }; } // namespace nachia; using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i<int(n); i++) #define repr(i,n) for(int i=int(n)-1; i>=0; i--) using Modint = atcoder::static_modint<998244353>; using namespace std; struct Node { i64 x; i64 c; }; Node op(Node l, Node r){ return Node{ l.x + r.x, l.c + r.c }; } Node mapping(Node f, Node x){ return Node{ f.x * x.x + f.c * x.c, x.c }; } Node composition(Node f, Node x){ return Node{ f.x * x.x, f.c + f.x * x.c }; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); i64 N; cin >> N; using Lst = nachia::LazySegtree<Node, Node, op, composition, mapping>; vector<i64> pf = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,57,59,61,67,71,73,79,83,89,97}; auto factor = [&](i64 a) -> vector<i64> { vector<i64> res(pf.size()); rep(d,pf.size()){ i64 p = pf[d]; i64 e = 0; while(a%p == 0){ a /= p; res[d]++; } } return res; }; auto lst = vector<Lst>(pf.size()); { vector<vector<Node>> init(pf.size(), vector<Node>(N, {0,1})); rep(i,N){ i64 a; cin >> a; auto f = factor(a); rep(d,f.size()) init[d][i].x = f[d]; } rep(i,pf.size()) lst[i] = Lst(init[i], {0,0}, {1,0}); } i64 Q; cin >> Q; rep(qi,Q){ i64 t; cin >> t; if(t == 1){ i64 l,r,a; cin >> l >> r >> a; l--; auto f = factor(a); rep(d,pf.size()) lst[d].apply(l,r,{0,f[d]}); } else if(t == 2){ i64 l,r,a; cin >> l >> r >> a; l--; auto f = factor(a); rep(d,pf.size()) lst[d].apply(l,r,{1,f[d]}); } else if(t == 3){ i64 l,r,a; cin >> l >> r >> a; l--; auto f = factor(a); vector<i64> rq(pf.size()); rep(d,pf.size()) if(pf[d] <= a) rq[d] = lst[d].prod(l,r).x; i64 ans = 1; for(auto d : rq){ ans *= d+1; ans %= 998244353; } cout << ans << "\n"; } } return 0; }