QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#786804#9625. 魔弹LinZhengyuWA 8ms25368kbC++145.6kb2024-11-26 23:36:242024-11-26 23:36:24

Judging History

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

  • [2024-11-26 23:36:24]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:25368kb
  • [2024-11-26 23:36:24]
  • 提交

answer

#include<bits/stdc++.h>
using std::cin;
using std::cout;
using std::pair;
using std::string;

typedef long long lli;

const int P=998244353;
const lli LM=8e18;
inline void LALM(lli&a,const lli b){if((a+=b)>=LM)a%=P;}//b=1e9*1e9
inline void AM(int&a,const int b){if((a+=b)>=P)a-=P;}
inline int AM2(int a,const int b){a+=b;return a>=P?a-P:a;}

inline int qpow(int x,int y){
	int z=1;
	for(;y;x=1ll*x*x%P,y>>=1)if(y&1)
		z=1ll*z*x%P;
	return z;
}
inline int inv(int x){return qpow(x,P-2);}

inline int jm(int x,int y){
	int z=1;
	for(int i=x;i>x-y;--i)
		z=1ll*z*i%P;
	return z;
}

namespace POLY {
//#ModBasic
//#UsefulCalc:qpow,inv
const int L=1<<19,G=3;//L:maxLength G:groot
int nv[L+5],og[L+5];

typedef std::vector<int> Poly;
inline void polyInit(int l){
    nv[1]=1;
    for(int i=2;i<l;++i)
        nv[i]=1ll*(P-P/i)*nv[P%i]%P;
    og[1]=1;
    for(int i=2;i<l;i<<=1){
        int d=qpow(G,(P-1)/(i*2));
        for(int j=i;j<i<<1;j+=2)
            og[j]=og[j>>1],og[j|1]=1ll*og[j]*d%P;
    }
}

inline int eval(const Poly a,int x){
    lli r=0;
    for(int i=0,y=1;i<a.size();++i,y=1ll*y*x%P)
        LALM(r,1ll*a[i]*y);
    return r%P;
}
inline int upl(int l){
    --l;
    l|=l>>1,l|=l>>2,l|=l>>4,l|=l>>8,l|=l>>16;
    return l+1;
}
inline void DIF(Poly&a,int l){
    for(int i=l>>1;i;i>>=1)
        for(int j=0;j<l;j+=i*2)
            for(int k=0;k<i;++k){
                int z=1ll*og[i|k]*(a[j|k]+P-a[j|i|k])%P;
                AM(a[j|k],a[j|i|k]),a[j|i|k]=z;
            }
}
inline void DFT(Poly&a,int l){
    for(int i=1;i<l;i<<=1)
        for(int j=0;j<l;j+=i*2)
            for(int k=0;k<i;++k){
                int z=1ll*og[i|k]*a[j|i|k]%P;
                a[j|i|k]=AM2(a[j|k],P-z),AM(a[j|k],z);
            }
}
inline void PDFT(Poly&a,int l){
    for(int i=0,z=P-(P-1)/l;i<l;++i)a[i]=1ll*a[i]*z%P;
    std::reverse(a.begin()+1,a.end());
}
Poly operator *(Poly a,Poly b){
    int l=a.size()+b.size()-1,ul=upl(l);
    a.resize(ul),b.resize(ul);
    DIF(a,ul),DIF(b,ul);
    for(int i=0;i<ul;++i)a[i]=1ll*a[i]*b[i]%P;
    DFT(a,ul);
    PDFT(a,ul);
    a.resize(l);
    return a;
}
inline Poly polyInv(Poly a){
	int l=a.size(),ul=upl(l);
	a.resize(ul);
	Poly b,c;
	b.resize(1),b[0]=inv(a[0]);
	for(int i=2;i<=ul;i<<=1){
		b.resize(i*2);
		DIF(b,i*2);
		c.resize(i);
		for(int j=0;j<i;++j)c[j]=a[j];
		c.resize(i*2);
		DIF(c,i*2);
		for(int j=0;j<i*2;++j)
			c[j]=(1ll*(P-c[j])*b[j]+2ll)%P*b[j]%P;
		DFT(c,i*2);
		PDFT(c,i*2);
		b.resize(i);
		for(int j=0;j<i;++j)b[j]=c[j];
	}
	b.resize(l);
	return b;
}
inline Poly polyDe(Poly a){
    Poly b(a.size());
    for(int i=0;i<b.size()-1;++i)b[i]=(i+1ll)*a[i+1]%P;
    b[b.size()-1]=0;
    return b;
}
inline Poly TMul(Poly a,Poly b){
	int la=a.size(),lb=b.size(),l=la+lb-1,ul=upl(l);
	a.resize(ul),b.resize(ul);
	std::reverse(b.begin()+1,b.end());
	for(int i=0,z=P-(P-1)/ul;i<ul;++i)b[i]=1ll*b[i]*z%P;
	DIF(a,ul),DIF(b,ul);
	for(int i=0;i<ul;++i)b[i]=1ll*a[i]*b[i]%P;
	DFT(b,ul);
	b.resize(lb);
	return b;
}

const int SN=1<<19;//SN: upl(N)*2

typedef std::vector<int> Vector;
Vector pq[SN+5];

void MPVInit(const Vector&b,int w,int l,int r){
	if(l==r){
		pq[w].resize(2);
		pq[w][0]=1,pq[w][1]=AM2(0,P-b[l]);
		return;
	}
	int mi=l+r>>1;
	MPVInit(b,w*2,l,mi),MPVInit(b,w*2+1,mi+1,r);
	pq[w]=pq[w*2]*pq[w*2+1];
}
void MPVDivide(int w,int l,int r,Poly a,Vector&b){
	a.resize(r-l+1);//?
	if(l==r){b[l]=a[0];return;}
	int mi=l+r>>1;
	MPVDivide(w*2,l,mi,TMul(pq[w*2+1],a),b);
	MPVDivide(w*2+1,mi+1,r,TMul(pq[w*2],a),b);
}
inline Vector multiPointValue(Poly a,Vector b){
	int l=std::max(a.size(),b.size());Vector r(l);
	a.resize(l+1),b.resize(l);//?
	MPVInit(b,1,0,l-1);
	MPVDivide(1,0,l-1,TMul(polyInv(pq[1]),a),r);
	r.resize(b.size());
	return r;
}
void dvd(Poly a[],int l,int r) {
	if(l==r)return;
	int mi=l+r>>1;
	dvd(a,l,mi),dvd(a,mi+1,r);
	a[l]=a[l]*a[mi+1];
}
};
using POLY::multiPointValue;
using POLY::polyDe;
using POLY::Poly;
using POLY::Vector;
using POLY::dvd;

const int N=1e5;

int n,jc;
string s;
int tk[N+5],tp;char c[N+5];

Poly a[N+5],b[N+5];int at,bt;
int ans[N+5];

int main() {
	std::ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);

	POLY::polyInit(POLY::L);

	cin>>n;
	jc=1;for(int i=1;i<=n;++i)jc=1ll*jc*i%P;
	cin>>s;
	for(int i=0;i<s.length();++i)
		if(i==0||s[i]!=c[tp])++tp,tk[tp]=1,c[tp]=s[i];
		else ++tk[tp];
	if(c[1]=='L'&&tp<3||c[1]=='R'&&tp<2) {
		for(int i=1;i<=tp;++i) {
			if(c[i]=='L') {
				for(int j=1;j<tk[i];++j)cout<<0<<' ';
				cout<<jc<<' ';
			}
			else {
				cout<<jc<<' ';
				for(int j=2;j<=tk[i];++j)cout<<0<<' ';
			}
		}
		return 0;
	}
	int i=1+(c[1]=='L'),s=1+(c[1]=='L')*tk[1];
	b[++bt].resize(2),b[bt][0]=P-s,b[bt][1]=1;
	for(;i<tp;s+=tk[i]+tk[i+1],i+=2) {
		a[++at].resize(2),a[at][0]=P-s-tk[i],a[at][1]=1;
		b[++bt].resize(2),b[bt][0]=P-s-tk[i]-tk[i+1],b[bt][1]=1;
	}
	dvd(a,1,at),dvd(b,1,bt);
	b[1]=polyDe(b[1]);
	Vector qv;
	i=1+(c[1]=='L'),s=1+(c[1]=='L')*tk[1];
	qv.emplace_back(s);
	for(;i<tp;s+=tk[i]+tk[i+1],i+=2)
		qv.emplace_back(s+tk[i]+tk[i+1]);
	Vector va=multiPointValue(a[1],qv),vb=multiPointValue(b[1],qv);
	i=1+(c[1]=='L'),s=1+(c[1]=='L')*tk[1];
	for(int j=0;i<tp;i+=2,++j) {
		ans[i]=1ll*jc*va[j]%P*inv(vb[j])%P;
		ans[i+1]=1ll*jc*va[j+1]%P*inv(vb[j+1])%P;
	}
	if(c[1]=='L')ans[1]=ans[2];
	if(c[tp]=='R')ans[tp]=ans[tp-1];
	for(int i=1;i<=tp;++i) {
		if(c[i]=='L') {
			for(int j=1;j<tk[tp];++j)cout<<0<<' ';
			cout<<ans[i]<<' ';
		}
		else {
			cout<<ans[i]<<' ';
			for(int j=2;j<=tk[i];++j)cout<<0<<' ';
		}
	}

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 25180kb

input:

2
RL

output:

1 1 

result:

ok single line: '1 1 '

Test #2:

score: 0
Accepted
time: 8ms
memory: 25108kb

input:

4
LLRR

output:

0 24 24 0 

result:

ok single line: '0 24 24 0 '

Test #3:

score: 0
Accepted
time: 3ms
memory: 25368kb

input:

4
RLRL

output:

9 6 6 9 

result:

ok single line: '9 6 6 9 '

Test #4:

score: -100
Wrong Answer
time: 3ms
memory: 25112kb

input:

10
LRLRLLRRRR

output:

0 0 0 1088640 1088640 0 0 0 604800 604800 0 0 0 1935360 1935360 0 0 0 

result:

wrong answer 1st lines differ - expected: '1088640 1088640 604800 604800 0 1935360 1935360 0 0 0', found: '0 0 0 1088640 1088640 0 0 0 60...00 0 0 0 1935360 1935360 0 0 0 '