QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#575 | #142586 | #6513. Expression 3 | ucup-team2335 | qzez | Failed. | 2024-03-14 15:31:24 | 2024-03-14 15:31:25 |
Details
Extra Test:
Accepted
time: 418ms
memory: 39432kb
input:
8 3 0 6 8 8 63 5 58 -++-+--
output:
2800
result:
ok 1 number(s): "2800"
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#142586 | #6513. Expression 3 | qzez | AC ✓ | 572ms | 78188kb | C++14 | 3.6kb | 2023-08-19 12:50:58 | 2024-02-14 13:28:39 |
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=31650,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+1,n+1);
// 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);
}