QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#61365#4411. Equipment UpgradeAFewSunsRE 0ms0kbC++143.4kb2022-11-12 17:12:322022-11-12 17:12:32

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-12 17:12:32]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2022-11-12 17:12:32]
  • 提交

answer

#include<bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
namespace my_std{
	#define ll int
	#define bl bool
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 8e18
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
#define mod 998244353
ll T,n,p[100010],c[100010],sum[100010],G[800080],g=3,rev[800080],lim=1;
ll W[2][24],F1[800080],F2[800080],a1[800080],a2[800080],b[800080];
void gcd(long long aa,long long bb,long long &x,long long &y){
    if(!bb) x=1,y=0;
    else gcd(bb,aa%bb,y,x),y-=x*(aa/bb);
}
il ll invv(long long aa){
    long long x,y;
    gcd(aa,mod,x,y);
    return (x+mod)%mod;
}
il void init(ll nn){
	lim=1;
	while(lim<(nn<<1)) lim<<=1;
	fr(i,0,lim-1) rev[i]=(rev[i>>1]>>1)|((i&1)?(lim>>1):0);
}
void NTT(ll *A,bl t){
	fr(i,0,lim-1) if(i<rev[i]) swap(A[i],A[rev[i]]);
	for(ll i=1,tmp=1;i<lim;i<<=1,tmp++){
		for(ll j=0;j<lim;j+=(i<<1)){
			ll w=1;
			fr(k,0,i-1){
				ll tmp1=A[j+k],tmp2=A[j+k+i];
				A[j+k]=(tmp1+1ll*tmp2*w%mod)%mod;
				A[j+k+i]=(tmp1-1ll*tmp2*w%mod+mod)%mod;
				w=1ll*w*W[t][tmp]%mod;
			}
		}
	}
	if(t){
		ll tmp=invv(lim);
		fr(i,0,lim-1) A[i]=1ll*A[i]*tmp%mod;
	}
}
void solve(ll l,ll r){
	if(l>n) return;
	if(l==r){
		if(l>n||!l) return;
		F1[l]=1ll*F1[l]*(mod+1-p[l-1])%mod*invv(sum[l])%mod;
		F2[l]=1ll*F2[l]*(mod+1-p[l-1])%mod*invv(sum[l])%mod;
		F1[l]=(F1[l-1]-F1[l]+mod)%mod;
		F2[l]=1ll*((long long)F2[l-1]-c[l-1]-F2[l]+mod+mod)%mod;
		F1[l]=1ll*F1[l]*invv(p[l-1])%mod;
		F2[l]=1ll*F2[l]*invv(p[l-1])%mod;
		return;
	}
	ll mid=(l+r)>>1;
	solve(l,mid);
	init(r-l+1);
	memset(a1,0,sizeof(int)*lim);
	memset(a2,0,sizeof(int)*lim);
	memcpy(a1,F1+l,sizeof(int)*(mid-l+1));
	memcpy(a2,F2+l,sizeof(int)*(mid-l+1));
	memcpy(b,G,sizeof(int)*(r-l+1));
//	fr(i,l,mid) a1[i-l]=F1[i];
//	fr(i,l,mid) a2[i-l]=F2[i];
//	fr(i,mid+1,r) a1[i-l]=a2[i-l]=0;
//	fr(i,l,r) b[i-l]=G[i-l];
	NTT(a1,0);
	NTT(a2,0);
	NTT(b,0);
	fr(i,0,lim) a1[i]=1ll*a1[i]*b[i]%mod;
	fr(i,0,lim) a2[i]=1ll*a2[i]*b[i]%mod;
	NTT(a1,1);
	NTT(a2,1);
	fr(i,mid+1,r) F1[i]=(F1[i]+a1[i-l])%mod;
	fr(i,mid+1,r) F2[i]=(F2[i]+a2[i-l])%mod;
	solve(mid+1,r);
}
int main(){
	W[0][23]=15311432;
	W[1][23]=invv(W[0][23]);
	pfr(i,22,0){
        W[0][i]=1ll*W[0][i+1]*W[0][i+1]%mod;
        W[1][i]=1ll*W[1][i+1]*W[1][i+1]%mod;
	}
	T=read();
	while(T--){
		n=read();
		fr(i,0,n-1){
			p[i]=1ll*read()*invv(100)%mod;
			c[i]=read();
		}
		fr(i,2,n){
			G[i]=read();
			sum[i]=(sum[i-1]+G[i])%mod;
		}
		while(lim<=n) lim<<=1;
		F1[0]=1;
		solve(0,lim-1);
		writeln(1ll*(mod-F2[n])*invv(F1[n])%mod);
		fr(i,2,n) G[i]=0;
		fr(i,0,lim-1) F1[i]=F2[i]=0;
	}
}
/*
283759603
931163558
520357380
641247289
958827760
*/

詳細信息

Test #1:

score: 0
Dangerous Syscalls

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:


result: