QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#858004 | #4411. Equipment Upgrade | xuzhihaodedie | AC ✓ | 933ms | 8524kb | C++20 | 2.5kb | 2025-01-16 12:07:36 | 2025-01-16 12:07:36 |
Judging History
answer
#include<cstdio>
#include<cctype>
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=100000,maxt=1<<18,MOD=998244353,INV100=828542813;
int te,n,p[maxn+5],c[maxn+5],w[maxn+5],sum[maxn+5],ans[maxn+5];
int wn[maxt+5],f[maxt+5],g[maxt+5];
#define EOLN(x) ((x)==10 || (x)==13 || (x)==EOF)
inline char readc(){
static char buf[100000],*l=buf,*r=buf;
return l==r && (r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<typename T> int readi(T &x){
T tot=0;char ch=readc(),lst='+';
while (!isdigit(ch)) {if (ch==EOF) return EOF;lst=ch;ch=readc();}
while (isdigit(ch)) tot=(tot<<3)+(tot<<1)+(ch^48),ch=readc();
lst=='-'?x=-tot:x=tot;return EOLN(ch);
}
inline int ADD(int x,int y) {return x+y>=MOD?x+y-MOD:x+y;}
inline int MUL(int x,int y) {return (LL)x*y%MOD;}
int Pow(int w,int b) {int s;for (s=1;b;b>>=1,w=MUL(w,w)) if (b&1) s=MUL(s,w);return s;}
void NTTPre(){
int x=Pow(3,(MOD-1)/maxt);
wn[maxt/2]=1;
for (int i=maxt/2+1;i<maxt;i++) wn[i]=MUL(wn[i-1],x);
for (int i=maxt/2-1;i>=0;i--) wn[i]=wn[i<<1];
}
void NTT(int *a,int n,int f){
if (f>0){
for (int k=n>>1;k;k>>=1)
for (int i=0;i<n;i+=k<<1)
for (int j=0;j<k;j++){
int x=a[i+j],y=a[i+j+k];
a[i+j+k]=MUL(x+MOD-y,wn[k+j]);
a[i+j]=ADD(x,y);
}
} else {
for (int k=1;k<n;k<<=1)
for (int i=0;i<n;i+=k<<1)
for (int j=0;j<k;j++){
int x=a[i+j],y=MUL(a[i+j+k],wn[k+j]);
a[i+j+k]=ADD(x,MOD-y);
a[i+j]=ADD(a[i+j],y);
}
for (int i=0,INV=MOD-(MOD-1)/n;i<n;i++) a[i]=MUL(a[i],INV);
reverse(a+1,a+n);
}
}
void Solve(int L,int R){
if (L==R){
if (L==1) {ans[L]=ADD(ans[L-1],c[L-1]);return;}
ans[L]=MUL(ans[L],p[L-1]+MOD-1);
ans[L]=MUL(ans[L],Pow(sum[L-1],MOD-2));
ans[L]=ADD(ans[L],ADD(ans[L-1],c[L-1]));
ans[L]=MUL(ans[L],Pow(p[L-1],MOD-2));
return;
}
int mid=L+(R-L>>1);
Solve(L,mid);
int t;for (t=1;t<=R-L-1+mid-L;t<<=1);
for (int i=0;i<=mid-L;i++) f[i]=ans[i+L];
for (int i=mid-L+1;i<t;i++) f[i]=0;
for (int i=0;i<=R-L-1;i++) g[i]=w[i];
for (int i=R-L;i<t;i++) g[i]=0;
NTT(f,t,1);NTT(g,t,1);
for (int i=0;i<t;i++) f[i]=MUL(f[i],g[i]);
NTT(f,t,-1);
for (int i=mid-L;i<=R-L-1;i++) ans[i+L+1]=ADD(ans[i+L+1],f[i]);
Solve(mid+1,R);
}
int main(){
NTTPre();
for (cin>>te;te;te--){
cin>>n;
for (int i=0;i<n;i++) cin>>p[i],p[i]=MUL(p[i],INV100),cin>>c[i];
for (int i=1;i<n;i++) cin>>w[i],sum[i]=ADD(sum[i-1],w[i]);
for (int i=0;i<=n;i++) ans[i]=0;
Solve(1,n);
cout<<ans[n]<<endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 933ms
memory: 8524kb
input:
208 2 100 41 28 64 28 3 100 48 91 13 73 3 78 92 4 100 22 15 85 26 50 41 15 90 85 77 5 100 39 51 97 83 41 4 86 36 70 49 24 17 33 6 100 53 53 45 92 2 36 40 61 61 76 52 18 37 75 49 96 7 100 5 21 47 39 58 78 1 82 93 59 82 56 90 1 41 76 64 84 27 8 100 14 38 77 66 20 1 63 47 47 3 12 87 16 99 62 14 81 75 2...
output:
375 243619761 141260443 516768753 850749960 897481401 602765935 510391586 689398435 784190268 697129546 505176530 687991734 16121189 684750916 616413796 324645467 60836964 997265902 829124402 135215114 115586183 566051860 45973142 577302112 438599189 808712026 903587073 180745041 931933480 429669755...
result:
ok 208 lines