QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#107444#6513. Expression 3psc233TL 373ms49876kbC++142.3kb2023-05-21 15:05:092023-05-21 15:06:50

Judging History

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

  • [2024-02-14 13:23:19]
  • hack成功,自动添加数据
  • (/hack/531)
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-21 15:06:50]
  • 评测
  • 测评结果:TL
  • 用时:373ms
  • 内存:49876kb
  • [2023-05-21 15:05:09]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define cs const
using namespace std;
cs int g=3;
const int N=6e5+10;
const int mod=998244353;
const int lim=1e6;
typedef vector<int> poly;
int rev[N],inv[N];
unordered_map<int,int>mp;
char s[N];
int n,m,len,d,x,k;
int a[N];
int mul(int x,int y){return (ll)x*y%mod;}
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int dec(int x,int y){return x-y>=0?x-y:x-y+mod;}
int ksm(int x,int y){
	ll ans=1;
	for (;y;y>>=1,x=mul(x,x)) if (y&1) ans=mul(ans,x);
	return ans;
}
int read(){
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9'){if (c=='-')f=-1;c=getchar();}
	while (c>='0'&&c<='9'){x=add(mul(x,10),c-'0');c=getchar();}
	return x; 
}
void init(int x){
	len=1,d=0;
	while (len<x) {len<<=1;d++;}
	for (int i=0;i<len;i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<(d-1));
}
inline poly NTT(poly a,int t) {
	for (int i=0;i<a.size();i++) if (i<rev[i]) swap(a[i],a[rev[i]]);
	for (int i=1;i<a.size();i<<=1) {
		int s=(i<<1);
		int wn=ksm(g,(mod-1)/s);
		if (t==-1) wn=ksm(wn,mod-2);
		for (int j=0;j<a.size();j+=s) {
			int w=1;
			for (int k=j;k<j+i;k++) {
				int x=a[k],y=mul(a[k+i],w);
				a[k]=add(x,y); a[k+i]=dec(x,y);
				w=mul(w,wn);
			}
		}
	}
	if (t==-1){
		ll w=ksm(a.size(),mod-2);
		for (int i=0;i<a.size();i++) a[i]=mul(a[i],w);
	}
	return a;
}
inline poly operator *(poly a,poly b){
	int n=a.size(),m=b.size(); 
	init(n+m-1);
	a.resize(len);
	b.resize(len);
	a=NTT(a,1); b=NTT(b,1);
	for (int i=0;i<a.size();i++) a[i]=mul(a[i],b[i]);
	a=NTT(a,-1);
	a.resize(n+m-1);
	return a;
}
const int sq=ksm(ksm(g,lim),mod-2);
int get(int x){
	if (x==0) return 0;
	for (int i=0,t=1;;t=mul(t,sq),i++){
		if (mp[mul(t,x)]){
			return i*lim+mp[mul(t,x)]-1;
		}
	}
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=0,t=1;i<lim;i++,t=mul(t,g)){
		mp[t]=i+1;
	}
	scanf("%s",s+1);
	poly b,c;
	for (int i=1;i<n;i++) if (s[i]=='-') b.pb(1); else b.pb(0);
	for (int i=1;i<=n;i++) c.pb(dec(get((i-2+mod)%mod),get(i))); 
	b=b*c;
	int ans=a[1];
	bool p=0;
	for (int i=2;i<=n;i++) if (s[i-2]!='-') {
		ans=add(ans,mul(a[i],ksm(g,b[i-2])));
	}
	for (int i=1;i<n;i++) ans=mul(ans,i);
	printf("%d\n",ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 373ms
memory: 49876kb

input:

4
9 1 4 1
-+-

output:

46

result:

ok 1 number(s): "46"

Test #2:

score: 0
Accepted
time: 343ms
memory: 49864kb

input:

5
1 2 3 4 5
+-+-

output:

998244313

result:

ok 1 number(s): "998244313"

Test #3:

score: -100
Time Limit Exceeded

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: