結果
問題 | No.2833 Count Taiko Results |
ユーザー |
|
提出日時 | 2024-08-02 23:58:15 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,038 bytes |
コンパイル時間 | 1,264 ms |
コンパイル使用メモリ | 87,224 KB |
実行使用メモリ | 18,016 KB |
最終ジャッジ日時 | 2024-08-02 23:58:31 |
合計ジャッジ時間 | 16,245 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 WA * 36 TLE * 3 -- * 15 |
ソースコード
#include<iostream> #include<cassert> #include<atcoder/modint> #include<atcoder/lazysegtree> using namespace std; using mint=atcoder::modint; using dat=pair<mint,int>; dat op(dat a,dat b){return make_pair(a.first+b.first,a.second+b.second);} dat e(){return make_pair(mint::raw(0),0);} dat mp(mint f,dat x){x.first*=f.pow(x.second);return x;} mint cmp(mint f,mint g){return f*g;} mint id(){return mint::raw(1);} int N; int A[2<<17],B[2<<17]; mint f(int K) { atcoder::lazy_segtree<dat,op,e,mint,mp,cmp,id>seg(N); mint ans=0,prod=1; mint R=1; for(int i=0;i<N;i++)R*=i<K?A[i]:A[i]+B[i]; for(int i=0;i+K<=N;i++) { mint cur=prod-seg.prod(0,i).first; seg.set(i,make_pair(cur,1)); int l=max(0,i-K+1); seg.apply(0,l,A[i]+B[i]); seg.apply(l,i+1,A[i]); prod*=A[i]+B[i]; ans+=cur*R; R/=A[i]; if(i+K<N)R=R/(A[i+K]+B[i+K])*A[i]; } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int K; cin>>N>>K; for(int i=0;i<N;i++)cin>>A[i]; for(int i=0;i<N;i++)cin>>B[i]; cout<<(f(K)-f(K+1)).val()<<endl; }