QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#142581#6513. Expression 3qzezRE 176ms21392kbC++143.6kb2023-08-19 12:41:402023-08-19 12:41:47

Judging History

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

  • [2024-02-14 13:23:19]
  • hack成功,自动添加数据
  • (/hack/531)
  • [2023-08-19 12:41:47]
  • 评测
  • 测评结果:RE
  • 用时:176ms
  • 内存:21392kb
  • [2023-08-19 12:41:40]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=(1<<19)+5,M=2e3+5,K=63,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,A[N];char s[N];ll frc[N],inv[N],Inv[N];
ll C(int x,int y){return frc[x]*Inv[y]%mod*Inv[x-y]%mod;}
ll mpow(ll x,int y=mod-2){ll ans=1;while(y) y&1&&(ans=ans*x%mod),y>>=1,x=x*x%mod;return ans;}
namespace LOG{
	const int g=3,Ig=mpow(g),step=1e3;
	const int N=1e6+5,M=1e5+5;
	pii A[N];int H;
	int ph,pr[M],Fl[M],f[M];
	int calc(int x){
		for(int i=0;;i++) {
			auto p=LB(A+1,A+H+1,make_pair(x,0));if(p->fi==x) return (p->se+i)%Mod;
			x=1ll*x*Ig%mod;
		}
		assert(0);return -1;
	}
	void Init(){
		int i,j;
		for(i=0;i<mod;i+=step) A[++H]=make_pair(mpow(g,i),i);sort(A+1,A+H+1);
		for(i=2;i<=K;i++) {
			if(!Fl[i]) pr[++ph]=i,f[i]=calc(i);
			for(int j=1;j<=ph&&i*pr[j]<=K;j++) {Fl[i*pr[j]]=1;f[i*pr[j]]=(f[i]+f[pr[j]])%Mod;if(i%pr[j]==0) break;}
		}
	}
	ll qry(int x){
		if(x<=K) return f[x];
		int q=mod/x,r=mod%x;
		if(r<x-r) return (qry(r)+(mod-1)/2-f[q]+Mod)%Mod;
		return (qry(x-r)-f[q+1]+Mod)%Mod;
	}
}
namespace Poly{
	#define CP complex<double>
	const int mod=998244352;
	int k,tr[N];CP C[N],D[N],f1[N],f2[N],O1[N],O2[N];const db pi=acos(-1);const int Wg=(1<<15);
	void Init(int p){for(k=1;k<=p;k<<=1);for(int i=0;i<k;i++) tr[i]=(tr[i>>1]>>1)|((i&1)?k/2:0);for(int i=0;i<k;i++) O1[i]={cos(2*pi/k*i),sin(2*pi/k*i)},O2[i]=conj(O1[i]);}
	void FFT(CP *A,int k,int Fl){
		int i,j,h;CP now;for(i=0;i<k;i++) tr[i]<i&&(swap(A[i],A[tr[i]]),0);
		for(i=2;i<=k;i<<=1){
			for(j=0;j<k;j+=i){
				for(h=j;h<j+i/2;h++) now=(Fl?O1[k/i*(h-j)]:O2[k/i*(h-j)])*A[h+i/2],A[h+i/2]=A[h]-now,A[h]+=now;
			}
		}if(Fl) return;for(i=0;i<k;i++) A[i]/=k;
	}
	ll Push(db x){return (ll)(x+0.5)%mod;}
	void mul(ll *A,ll *B,ll *G,int n,int m){
		int i;Init(n+m);
		for(i=0;i<k;i++) C[i]=(CP){0,0};for(i=0;i<n;i++) C[i]=(CP){A[i]/Wg*1.0,A[i]%Wg*1.0};
		FFT(C,k,1);for(i=0;i<k;i++) D[i]=conj(C[(k-i)%k]),f1[i]=(C[i]+D[i])*0.5,f2[i]=(D[i]-C[i])*(CP){0,1}*0.5;
		for(i=0;i<k;i++) C[i]=(CP){0,0};for(i=0;i<m;i++) C[i]=(CP){B[i]/Wg*1.0,B[i]%Wg*1.0};
		FFT(C,k,1);for(i=0;i<k;i++) f1[i]=f1[i]*C[i],f2[i]=f2[i]*C[i];
		FFT(f1,k,0);FFT(f2,k,0);for(i=0;i<n+m;i++) G[i]=(Push(f1[i].real())*Wg*Wg%mod+(Push(f1[i].imag())+Push(f2[i].real()))*Wg%mod+Push(f2[i].imag()))%mod;
	}
}
ll f[N],c[N],b[N],d[N];
int main(){
	int i,j;LOG::Init();
	scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%d",&A[i]);
	scanf("%s",s+1);
	for(frc[0]=i=1;i<=n;i++) frc[i]=frc[i-1]*i%mod;
	inv[1]=1;for(i=2;i<=n;i++) inv[i]=(mod-inv[mod%i])*(mod/i)%mod;
	for(Inv[0]=i=1;i<=n;i++) Inv[i]=Inv[i-1]*inv[i]%mod;
	for(i=1;i<=n;i++) f[i]=LOG::qry(i);
	for(i=1;i<n;i++) b[i]=(s[i]=='+'?0:1);
	for(i=3;i<=n;i++) c[i]=(f[i-2]-f[i]+Mod)%Mod;
	Poly::mul(b,c,d,n,n);
	// cerr<<c[3]<<' '<<d[5]<<' '<<f[3]<<'\n';
	ll ans=A[1]*frc[n-1]%mod;
	ll Sum=0;
	for(i=2;i<=n;i++){
		ll tot=(s[i-1]=='+'?0:Mod/2);
		if(i>2){
			if(i>3) Sum+=f[i-1];
			if(s[i-2]=='-') continue;
			tot+=f[2];
			if(i>3) tot+=Sum+d[i];
		} 
		tot%=Mod;
		// cerr<<mpow(LOG::g,tot)<<'\n';
		// cerr<<tot*frc[i-2]%mod<<'\n';
		ans+=mpow(LOG::g,tot)*C(n-1,n-i)%mod*frc[n-i]%mod*A[i]%mod;
	}
	printf("%lld\n",ans%mod);
}

详细

Test #1:

score: 100
Accepted
time: 176ms
memory: 20804kb

input:

4
9 1 4 1
-+-

output:

46

result:

ok 1 number(s): "46"

Test #2:

score: 0
Accepted
time: 172ms
memory: 21392kb

input:

5
1 2 3 4 5
+-+-

output:

998244313

result:

ok 1 number(s): "998244313"

Test #3:

score: -100
Runtime Error

input:

100000
664815434 205025136 871445392 797947979 379688564 336946672 231295524 401655676 526374414 670533644 156882283 372427821 700299596 166140732 677498490 44858761 185182210 559696133 813911251 842364231 681916958 114039865 222372111 784286397 437994571 152137641 650875922 613727135 209302742 5321...

output:


result: