結果
問題 | No.1548 [Cherry 2nd Tune B] 貴方と私とサイクルとモーメント |
ユーザー | 👑 Nachia |
提出日時 | 2021-06-11 21:44:49 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 111 ms / 4,500 ms |
コード長 | 3,409 bytes |
コンパイル時間 | 1,402 ms |
コンパイル使用メモリ | 105,764 KB |
実行使用メモリ | 23,296 KB |
最終ジャッジ日時 | 2024-05-08 17:21:02 |
合計ジャッジ時間 | 6,350 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 82 ms
13,056 KB |
testcase_03 | AC | 25 ms
8,320 KB |
testcase_04 | AC | 71 ms
21,708 KB |
testcase_05 | AC | 8 ms
5,376 KB |
testcase_06 | AC | 55 ms
11,932 KB |
testcase_07 | AC | 60 ms
23,040 KB |
testcase_08 | AC | 74 ms
13,384 KB |
testcase_09 | AC | 55 ms
8,832 KB |
testcase_10 | AC | 63 ms
21,120 KB |
testcase_11 | AC | 67 ms
21,552 KB |
testcase_12 | AC | 40 ms
5,760 KB |
testcase_13 | AC | 46 ms
21,376 KB |
testcase_14 | AC | 63 ms
7,808 KB |
testcase_15 | AC | 50 ms
23,244 KB |
testcase_16 | AC | 66 ms
13,952 KB |
testcase_17 | AC | 98 ms
20,864 KB |
testcase_18 | AC | 68 ms
22,656 KB |
testcase_19 | AC | 33 ms
7,936 KB |
testcase_20 | AC | 48 ms
21,888 KB |
testcase_21 | AC | 50 ms
12,160 KB |
testcase_22 | AC | 100 ms
23,168 KB |
testcase_23 | AC | 101 ms
23,296 KB |
testcase_24 | AC | 100 ms
23,168 KB |
testcase_25 | AC | 104 ms
23,296 KB |
testcase_26 | AC | 102 ms
23,296 KB |
testcase_27 | AC | 101 ms
23,168 KB |
testcase_28 | AC | 102 ms
23,296 KB |
testcase_29 | AC | 100 ms
23,296 KB |
testcase_30 | AC | 101 ms
23,168 KB |
testcase_31 | AC | 100 ms
23,168 KB |
testcase_32 | AC | 79 ms
23,168 KB |
testcase_33 | AC | 81 ms
23,296 KB |
testcase_34 | AC | 79 ms
23,168 KB |
testcase_35 | AC | 78 ms
23,168 KB |
testcase_36 | AC | 77 ms
23,168 KB |
testcase_37 | AC | 111 ms
23,296 KB |
testcase_38 | AC | 76 ms
23,288 KB |
testcase_39 | AC | 80 ms
23,156 KB |
testcase_40 | AC | 80 ms
23,168 KB |
testcase_41 | AC | 82 ms
23,296 KB |
ソースコード
#include <iostream> #include <vector> #include <atcoder/modint> #include <atcoder/segtree> using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) using mll = atcoder::static_modint<998244353>; template< class S, S(*op)(S a, S b), S(*e)(), class F, S(*mapping)(F a, S b), F(*composition)(F a, F b), F(*id)() > struct lazy_segtree{ private: struct Node{ S v; F r; }; int N,logN; vector<Node> V; void mapF(int i,F f){ V[i].v = mapping(f,V[i].v); V[i].r = composition(f,V[i].r); } void merge(int i){ V[i].v = mapping(V[i].r,op(V[i*2].v,V[i*2+1].v)); } void spread(int i){ mapF(i*2,V[i].r); mapF(i*2+1,V[i].r); V[i].r=id(); } public: lazy_segtree(int n){ N=1; logN=0; while(N<n){ N*=2; logN++; } V.assign(N*2,{ e(),id() }); } lazy_segtree(vector<S> A) : lazy_segtree(A.size()){ rep(i,A.size()) V[N+i].v=A[i]; for(int i=N-1; i>=1; i--) merge(i); } void set(int p,S v){ p+=N; for(int d=logN; d>=1; d--) spread(p>>d); V[p].v=v; for(int d=1; d<=logN; d++) merge(p>>d); } S get(int p){ p+=N; for(int d=logN; d>=1; d--) spread(p>>d); return V[p].v; } S prod(int l,int r){ l+=N; r+=N; for(int d=logN; d>=1; d--){ spread(l>>d); spread((r-1)>>d); } S ql=e(), qr=e(); while(l<r){ if(l&1) ql=op(ql,V[l++].v); if(r&1) qr=op(V[--r].v,qr); l/=2; r/=2; } return op(ql,qr); } void apply(int p,F f){ p+=N; for(int d=logN; d>=1; d--) spread(p>>d); mapF(p,f); for(int d=1; d<=logN; d++) merge(p>>d); } void apply(int l,int r,F f){ l+=N; r+=N; for(int d=logN; d>=1; d--){ spread(l>>d); spread((r-1)>>d); } int lp=l, rp=r; while(l<r){ if(l&1) mapF(l++,f); if(r&1) mapF(--r,f); l/=2; r/=2; } for(int d=1; d<=logN; d++){ merge(lp>>d); merge((rp-1)>>d); } } }; struct S { mll G[5]; }; S op(S l, S r) { S res; rep(i,5) res.G[i] = l.G[i] + r.G[i]; return res; } S e() { return { {0,0,0,0,0} }; } struct F { int upd; }; S mapping(F f, S a) { if(f.upd != -1){ rep(t,4) a.G[t+1] = a.G[t] * f.upd; } return a; } F composition(F f, F g) { return (f.upd == -1) ? g : f; } F id() { return { -1 }; } using RQ = lazy_segtree<S, op, e, F, mapping, composition, id>; int N; vector<S> A; RQ G(0); int Q; int main(){ cin >> N; A.resize(N); rep(i,N){ int a; cin >> a; A[i].G[0] = 1; rep(t,4) A[i].G[t+1] = A[i].G[t] * a; } G = RQ(A); cin >> Q; rep(q,Q){ int t,u,v,w; cin >> t >> u >> v >> w; u--; v--; w--; if(u > v) swap(u,v); int l1, r1, l2, r2; if(u <= w && w <= v){ l1=u; r1=v+1; l2=0; r2=0; } else{ l1=v; r1=N; l2=0; r2=u+1; } if(t == 0){ int b; cin >> b; G.apply(l1,r1,{b}); G.apply(l2,r2,{b}); } else{ S x = op( G.prod(l1,r1) , G.prod(l2,r2) ); vector<mll> coe; mll M = x.G[1] * x.G[0].inv(); if(t == 1) coe = {-M,1,0,0,0}; if(t == 2) coe = {M*M,-M*2,1,0,0}; if(t == 3) coe = {-M*M*M,M*M*3,-M*3,1,0}; if(t == 4) coe = {M*M*M*M,-M*M*M*4,M*M*6,-M*4,1}; mll ans = 0; rep(t,5) ans += x.G[t] * coe[t]; ans /= x.G[0]; cout << ans.val() << "\n"; } } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_inst;