QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#41307 | #4411. Equipment Upgrade | DaBenZhongXiaSongKuaiDi# | AC ✓ | 1485ms | 15816kb | C++14 | 2.8kb | 2022-07-29 14:44:35 | 2022-07-29 14:44:36 |
Judging History
answer
#include <bits/stdc++.h>
#define mod 998244353
using namespace std;
inline int read()
{
int n=0,f=1,ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
n=n*10+ch-'0';
ch=getchar();
}
return n*f;
}
inline int add(int x,int y)
{
if(x+y>=mod)return x+y-mod;
return x+y;
}
inline int dec(int x,int y)
{
if(x-y<0)return x-y+mod;
return x-y;
}
inline int mul(int x,int y)
{
return 1LL*x*y-1LL*x*y/mod*mod;
}
inline int ksm(int n,int k)
{
int ans=1;
while(k>=1)
{
if(k&1)ans=mul(ans,n);
n=mul(n,n);
k>>=1;
}
return ans;
}
int r[500001];
int cf[1<<19],ncf[1<<19];
inline void ntt(int* f,int tr,int flag)
{
for(int i=0;i<tr;i++)if(i<r[i])swap(f[i],f[r[i]]);
for(int j=1;j<tr;j<<=1)
{
int ws=(1<<19)/(j<<1);
for(int k=0;k<tr;k+=(j<<1))
{
for(int l=0;l<j;l++)
{
int sthe=f[k+l],sth=mul(f[k+j+l],(flag==1?cf[l*ws]:ncf[l*ws]));
f[k+l]=add(sthe,sth);
f[k+j+l]=dec(sthe,sth);
}
}
}
if(flag==-1)
{
int sth=ksm(tr,mod-2);
for(int i=0;i<tr;i++)f[i]=mul(f[i],sth);
}
}
int x[400001],y[400001];
inline void mul(int* a,const int* b,int tr,int lll)
{
for(int i=0;i<tr;i++)x[i]=a[i],y[i]=b[i];
for(int i=0;i<tr;i++)r[i]=(r[i>>1]>>1)|((i&1)<<(lll-1));
ntt(x,tr,1);
ntt(y,tr,1);
for(int i=0;i<tr;i++)x[i]=mul(x[i],y[i]);
ntt(x,tr,-1);
for(int i=0;i<tr;i++)a[i]=x[i];
}
int p[100005],c[100005];
int f[100005];
int ta[400005],tb[400005];
int qzf[100005];
int w[100005],qzw[100005];
void solve(int l,int r)
{
if(l==r)
{
f[l]=(1LL*qzw[l-1]*qzf[l-1]%mod+mod-f[l])%mod;
//printf("%d\n",f[l]);
f[l]=(1LL*(mod+1-p[l])*f[l]%mod*ksm(qzw[l-1],mod-2)%mod+c[l])%mod;
f[l]=1LL*ksm(p[l],mod-2)*f[l]%mod;
qzf[l]=(qzf[l-1]+f[l])%mod;
//printf("%d %d %lld\n",l,f[l],7LL*f[l]%mod);
return;
}
int mid=(l+r)>>1;
solve(l,mid);
int tr=1,lll=0;
for(int i=l;i<=mid;i++)ta[i-l]=f[i];
tb[0]=tb[1]=0;
for(int i=2;i<=r-l;i++)tb[i]=qzw[i-1];
while(tr<=r-l+mid-l)tr<<=1,lll++;
for(int i=mid-l+1;i<tr;i++)ta[i]=0;
for(int i=r-l+1;i<tr;i++)tb[i]=0;
mul(ta,tb,tr,lll);
for(int i=mid+1;i<=r;i++)
{
f[i]=(f[i]+ta[i-l])%mod;
}
solve(mid+1,r);
}
signed main()
{
int g=ksm(3,(mod-1)/(1<<19)),ng=ksm(g,mod-2);
cf[0]=ncf[0]=1;
for(int i=1;i<(1<<19);i++)
{
cf[i]=mul(cf[i-1],g);
ncf[i]=mul(ncf[i-1],ng);
}
int t,n;
t=read();
for(int greg=1;greg<=t;greg++)
{
n=read();
for(int i=1;i<=n;i++)
{
p[i]=read();
p[i]=1LL*p[i]*ksm(100,mod-2)%mod;
c[i]=read();
}
qzw[0]=0;
for(int i=1;i<=n-1;i++)
{
w[i]=read();
qzw[i]=(qzw[i-1]+w[i])%mod;
}
for(int i=1;i<=n;i++)f[i]=0;
solve(1,n);
printf("%d\n",qzf[n]);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1485ms
memory: 15816kb
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