QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#58671#4411. Equipment Upgradeqinjianbin#AC ✓2176ms25952kbC++172.5kb2022-10-27 12:18:142022-10-27 12:18:14

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-27 12:18:14]
  • 评测
  • 测评结果:AC
  • 用时:2176ms
  • 内存:25952kb
  • [2022-10-27 12:18:14]
  • 提交

answer

#include<iostream>
using namespace std;

typedef long long LL;

const int mod =998244353;
const int maxn =1<<20;

int n;
LL w[maxn],sumW[maxn];
int c[maxn];
LL p[maxn],inv100;

LL a[maxn],b[maxn];
LL qhy[maxn],cjm[maxn];
LL f[maxn],sumF[maxn];

LL g[maxn];

LL inv2[maxn];

LL qpow(LL x,LL y,int mod)
{
	LL res=1;
	for(;y;y>>=1,x=x*x%mod)
		if (y&1) res=res*x%mod;
	return res;
}

int pos[maxn];
void preprocess(int len)
{
	int i;
	for(i=1;i<len;i++) pos[i]=(pos[i>>1]>>1)|((len>>1)*(i&1));
	g[0]=1;
	g[1]=qpow(3,(mod-1)/len,mod);
	for(i=2;i<len;i++) g[i]=g[i-1]*g[1]%mod;
}

void FNTT(LL *a,bool flag,int len)
{
	int i,j,k,w;
	LL u,v;
	for(i=1;i<len;i++)
		if (i<pos[i]) a[i]^=a[pos[i]]^=a[i]^=a[pos[i]];
	for(i=2;i<=len;i<<=1)
		for(j=0;j<len;j+=i)
			for(w=k=0;k<(i>>1);k++,w+=len/i)
			{
				u=a[j+k];
				v=a[j+(i>>1)+k]*g[flag?w:(len-w)%len]%mod;
				a[j+k]=(u+v)%mod;
				a[j+(i>>1)+k]=(u-v)%mod;
			}
}

void mul(LL *cxy,LL *dxj,LL *c,int n,int m)
{
	int i,len;
	int index;
	for(len=1,index=0;len<n+m-1;len<<=1,index++);
	preprocess(len);
	for(i=0;i<n;i++) a[i]=cxy[i];
	for(;i<len;i++) a[i]=0;
	for(i=0;i<m;i++) b[i]=dxj[i];
	for(;i<len;i++) b[i]=0;

	FNTT(a,true,len);
	FNTT(b,true,len);
	for(i=0;i<len;i++) c[i]=a[i]*b[i]%mod;
	FNTT(c,false,len);
	for(i=0;i<len;i++) 
	{
		c[i]=c[i]*inv2[index]%mod;
		if (c[i]<0) c[i]+=mod;
	}
}

void standing_by()
{
	int i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lld%d",&p[i],&c[i]);
		p[i]=p[i]*inv100%mod;
	}

	for(i=1;i<n;i++)
	{
		scanf("%lld",&w[i]);
		sumW[i]=sumW[i-1]+w[i];
	}

	for(i=0;i<=n;i++) f[i]=0;
	for(i=0;i<=n;i++) sumF[i]=0;
}

void solve(int l,int r)
{
	if (l==r)
	{
		//printf("%d %lld\n",l,f[l]);
		f[l]=c[l]+(1-p[l])*sumF[l]%mod-(1-p[l])*f[l]%mod*qpow(sumW[l],mod-2,mod)%mod;
		f[l]%=mod;
		f[l]=f[l]*qpow(p[l],mod-2,mod)%mod;
		if (f[l]<0) f[l]+=mod;
		sumF[l+1]=(sumF[l]+f[l])%mod;
		//printf("%d %lld\n",l+1,sumF[l+1]);
		return ;
	}

	int mid=(l+r)>>1;
	int i,j,k;

	solve(l,mid);

	for(i=0,j=l;j<=mid;i++,j++)
	{
		cjm[i]=sumF[j];
	}

	mul(cjm,w,qhy,mid-l+1,r-l+1);

	for(i=mid+1;i<=r;i++)
		f[i]=(f[i]+qhy[i-l])%mod;

	solve(mid+1,r);
}

void complete()
{
	solve(0,n-1);
	printf("%lld\n",sumF[n]);
}

int main()
{
	int t,i;
	inv100=qpow(100,mod-2,mod);
	inv2[0]=1;
	inv2[1]=(mod+1)>>1;
	for(i=2;i<maxn;i++)
		inv2[i]=inv2[i-1]*inv2[1]%mod;
	scanf("%d",&t);
	for(;t;t--)
	{
		standing_by();
		complete();
	}
	return 0;
}

/*
1
3
100 1
70 2
50 3
2 3
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2176ms
memory: 25952kb

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