QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#765247#9625. 魔弹275307894a#TL 518ms31500kbC++146.6kb2024-11-20 13:21:182024-11-20 13:21:19

Judging History

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

  • [2024-11-20 13:21:19]
  • 评测
  • 测评结果:TL
  • 用时:518ms
  • 内存:31500kb
  • [2024-11-20 13:21:18]
  • 提交

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
#define eb emplace_back
#define all(x) x.begin(),x.end()
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>;
const int N=1e5+5,M=N*4+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(28382);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;

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 P=998244353,g=3;
	ll mpow(ll x,int y=P-2){ll ans=1;while(y) y&1&&(ans=ans*x%P),y>>=1,x=x*x%P;return ans;}
	int Ig;
    const int N=2e6,M=2e6,step=1e3,K=31700;
    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)%(P-1);
            x=1ll*x*Ig%P;
        }
        assert(0);return -1;
    }
    void Init(){
        int i,j;Ig=mpow(g);
        for(i=0;i<P;i+=step) A[++H]=make_pair(mpow(g,i),i);sort(A+1,A+H+1);
        for(i=2;i<=K&&i<P;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]])%(P-1);if(i%pr[j]==0) break;}
        }
    }
    ll qry(int x){
        if(x<=K) return f[x];
        int q=P/x,r=P%x;
        if(r<x-r) return (qry(r)+(P-1)/2-f[q]+(P-1))%(P-1);
        return (qry(x-r)-f[q+1]+(P-1))%(P-1);
    }
}


const int P=mod-1;
using polyM=vector<ll>;
namespace PolyM{
	const int N=(1<<21)+5;
	using cp=complex<db>;
	int k,tr[N];cp pw[N];
	const db pi=acos(-1);const int Base=(1<<15);
	ll mpow(ll x,int y=P-2){ll ans=1;while(y) y&1&&(ans=ans*x%P),y>>=1,x=x*x%P;return ans;}
	void init(int n){
		for(k=2;k<=n;k<<=1);
		for(int i=0;i<k;i++) tr[i]=(tr[i>>1]>>1)|(i&1?k/2:0);
		for(int i=k/2;i<k;i++) pw[i]=cp(cos(2*pi/k*(i-k/2)),sin(2*pi/k*(i-k/2)));
		for(int i=k/2-1;i;i--) pw[i]=pw[i<<1];
	}
	void fft(cp *A,int k,int flag){
		for(int i=0;i<k;i++) if(i<tr[i]) swap(A[i],A[tr[i]]);
		for(int i=2;i<=k;i<<=1){
			cp *e=pw+i/2;
			for(int j=0;j<k;j+=i){
				for(int h=j;h<j+i/2;h++){
					cp x=A[h+i/2]*e[h-j];
					A[h+i/2]=A[h]-x;A[h]+=x;
				}
			}
		}
		if(flag) return;
		reverse(A+1,A+k);
		for(int i=0;i<k;i++) A[i]/=k;
	}
	ll round(db x){return ll(x+0.5)%P;}
	namespace Public{
		polyM operator *(const polyM &A,const polyM &B){
			if(A.empty()||B.empty()) return polyM({});
			static cp a[N],b[N],c[N],d[N];
			init(A.size()+B.size());
			for(int i=0;i<A.size();i++) a[i]=cp(A[i]/Base,A[i]%Base);fill(a+A.size(),a+k,0);
			for(int i=0;i<B.size();i++) b[i]=cp(B[i]/Base,B[i]%Base);fill(b+B.size(),b+k,0);
			fft(a,k,1);fft(b,k,1);
			for(int i=0;i<k;i++){
				cp x=conj(a[(k-i)%k]);
				c[i]=(x+a[i])*cp(0.5,0)*b[i];
				d[i]=(x-a[i])*cp(0,0.5)*b[i];
			}
			fft(c,k,0);fft(d,k,0);
			polyM C(A.size()+B.size()-1);
			for(int i=0;i<C.size();i++) C[i]=((round(c[i].real())*Base+round(c[i].imag()+d[i].real()))*Base+round(d[i].imag()))%P;
			return C;
		}
		polyM& operator *=(polyM &A,const polyM &B){
			return A=A*B;
		}
		polyM operator /(const polyM &A,const polyM &B){
			polyM C=A,D=B;
			reverse(D.begin(),D.end());
			C*=D;
			return polyM(C.begin()+int(D.size())-1,C.end());
		}
		polyM& operator /=(polyM &A,const polyM &B){
			return A=A/B;
		}
		polyM operator *(const polyM &A,const int &B){
			polyM C=A;for(auto &i:C) (i*=B)%=P;
			return C;
		}
		polyM& operator *=(polyM &A,const int &B){
			return A=A*B;
		}
		polyM operator +(const polyM &A,const polyM &B){
			polyM C(max(A.size(),B.size()));
			for(int i=0;i<A.size();i++) C[i]=A[i];
			for(int i=0;i<B.size();i++) (C[i]+=B[i])%=P;
			return C;
		}
		polyM& operator +=(polyM &A,const polyM &B){
			return A=A+B;
		}
		polyM operator -(const polyM &A,const polyM &B){
			polyM C(max(A.size(),B.size()));
			for(int i=0;i<A.size();i++) C[i]=A[i];
			for(int i=0;i<B.size();i++) (C[i]+=P-B[i])%=P;
			return C;
		}
		polyM& operator -=(polyM &A,const polyM &B){
			return A=A-B;
		}
		polyM operator %(const polyM &A,const int &B){
			polyM C=A;
			if(C.size()>B) C.resize(B);
			return C;
		}
		polyM& operator %=(polyM &A,const int B){
			return A=A%B;
		}
		polyM operator <<(const polyM &A,const int &B){
			polyM C(A.size()+B);
			copy(all(A),C.begin()+B);
			return C;
		}
		polyM& operator <<=(polyM &A,const int &B){
			return A=A<<B;
		}
		polyM operator >>(const polyM &A,const int &B){
			if(B>=A.size()) return polyM({});
			return polyM(A.begin()+B,A.end());
		}
		polyM& operator >>=(polyM &A,const int &B){
			return A=A>>B;
		}
		polyM inve(polyM A,int n=-1){
			if(n==-1) n=A.size();
			if(n==1) return polyM({1});
			polyM A0=inve(A%(n+1>>1),n+1>>1);
			return A0*(polyM({2})-A*A0%n)%n;
		}
	}
}using namespace PolyM::Public;



int n;
char s[N];
ll inv[N],f1[N],f2[N],frc[N],frv[N];
ll C(int x,int y){return frc[x]*frv[y]%mod*frv[x-y]%mod;}
ll w[N];
void Solve(){
	scanf("%d%s",&n,s+1);
	s[0]='L';s[n+1]='R';
	inv[1]=1;for(int i=2;i<=n;i++) inv[i]=(mod-inv[mod%i])*(mod/i)%mod;
	for(int i=frc[0]=frv[0]=1;i<=n;i++) frc[i]=frc[i-1]*i%mod,frv[i]=frv[i-1]*inv[i]%mod;
	LOG::Init();
	for(int i=1;i<=n;i++) w[i]=LOG::calc(1+inv[i]);
	polyM F1(n+1),G1(n+1);
	for(int i=1;i<=n;i++) F1[i]=(s[i]=='L'?1:0),G1[i]=w[i];
	F1*=G1;
	for(int i=1;i<=n;i++) if(s[i]=='L') f1[i]=F1[i];
	polyM F2(n+1),G2(n+1);
	for(int i=1;i<=n;i++) F2[i]=(s[i]=='R'?1:0),G2[i]=w[i];
	F2/=G2;
	for(int i=1;i<=n;i++) if(s[i]=='R') f2[i]=F2[i];
	

	for(int i=0;i<=n+1;i++){
		if(s[i]=='L') f1[i]=mpow(3,f1[i]);
		else f2[i]=mpow(3,f2[i]);
	} 
	for(int i=1;i<=n;i++){
		if(s[i]=='L') f1[i]=f1[i]*frc[i-1]%mod;
		else f2[i]=f2[i]*frc[n-i]%mod;
	}
	for(int i=1;i<=n;i++){
		ll w=0;
		if(s[i]=='L'&&s[i+1]=='R') w=f1[i]*f2[i+1]%mod*C(n,i)%mod;
		if(s[i]=='R'&&s[i-1]=='L') w=f1[i-1]*f2[i]%mod*C(n,i-1)%mod;
		printf("%lld%c",w," \n"[i==n]);
	}
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 433ms
memory: 28864kb

input:

2
RL

output:

1 1

result:

ok single line: '1 1'

Test #2:

score: 0
Accepted
time: 430ms
memory: 30480kb

input:

4
LLRR

output:

0 24 24 0

result:

ok single line: '0 24 24 0'

Test #3:

score: 0
Accepted
time: 421ms
memory: 31416kb

input:

4
RLRL

output:

9 6 6 9

result:

ok single line: '9 6 6 9'

Test #4:

score: 0
Accepted
time: 425ms
memory: 30280kb

input:

10
LRLRLLRRRR

output:

1088640 1088640 604800 604800 0 1935360 1935360 0 0 0

result:

ok single line: '1088640 1088640 604800 604800 0 1935360 1935360 0 0 0'

Test #5:

score: 0
Accepted
time: 431ms
memory: 29432kb

input:

10
LLRLLRLRLL

output:

0 725760 725760 0 725760 725760 483840 483840 0 1693440

result:

ok single line: '0 725760 725760 0 725760 725760 483840 483840 0 1693440'

Test #6:

score: 0
Accepted
time: 503ms
memory: 31500kb

input:

998
RLRLRLRLRLRLRLRLRLRLRLRLRLRLRRLLRRRLRLLRLLRLRLRLLLRLRRLRLRLRLRLRLRLRLRLRLRLRLRLRRLRLLRLRLRLRLRLRLRLRRLRLLRLRLRLRLRLRLRRLRRLRRRLLRLLRLRLLRRLRLLLRLRLRRLRRLRLRLRRLRLRLLRLRLRLRLRLRLRLLRLRLRLRLRLLLRRLLRLRRLRRLRRLRLRLRLRLRLRLRLRLRLRLRLRLLRRLRRRLRRLRLRRLRLRLRLRLRLRLRLLRLLRRLRRLRLLRLRLRLRRLLRLRLRLLRRLRL...

output:

791892921 222105954 222105954 387243673 387243673 858332170 858332170 668690160 668690160 29037702 29037702 344898397 344898397 10138435 10138435 920091431 920091431 680236417 680236417 884390492 884390492 338820980 338820980 508576275 508576275 957551010 957551010 2459479 2459479 0 0 61773050 61773...

result:

ok single line: '791892921 222105954 222105954 ...0 632970969 632970969 464724562'

Test #7:

score: 0
Accepted
time: 503ms
memory: 29500kb

input:

998
RLRLRLRLRLRLRLRLRLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRRLRLRLRLRLRLRLRLRLRLRLRLRLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRRLRLRLRLRLRLRLRLRRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLR...

output:

439674742 509947875 509947875 815063904 815063904 891776804 891776804 553641803 553641803 13450200 13450200 267859496 267859496 385670319 385670319 882911667 882911667 109331874 109331874 0 128425033 128425033 836729978 836729978 854828800 854828800 123260213 123260213 415537062 415537062 26751346 2...

result:

ok single line: '439674742 509947875 509947875 ...2 773862752 498604661 498604661'

Test #8:

score: 0
Accepted
time: 499ms
memory: 29156kb

input:

1000
LRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRL...

output:

255385 255385 948987885 948987885 944375949 944375949 391954880 391954880 918617102 918617102 509797789 509797789 963771001 963771001 168738152 168738152 967324970 967324970 550867915 550867915 149529568 149529568 490172856 490172856 731868859 731868859 286624466 286624466 277467460 277467460 496196...

result:

ok single line: '255385 255385 948987885 948987...4 705333897 705333897 531622062'

Test #9:

score: 0
Accepted
time: 500ms
memory: 29560kb

input:

998
LRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLR...

output:

54273261 54273261 171633438 171633438 946148426 946148426 982991957 982991957 138042735 138042735 703892213 703892213 165685072 165685072 890250227 890250227 244374543 244374543 640936104 640936104 169345002 169345002 847600184 847600184 889380235 889380235 648465375 648465375 412924715 412924715 37...

result:

ok single line: '54273261 54273261 171633438 17...438 171633438 54273261 54273261'

Test #10:

score: 0
Accepted
time: 518ms
memory: 29248kb

input:

999
RLRRLRRRLLLLLLLRRRRLRLLRLRRLLLLRRLLRRRRLRRLRLLRRRLLLLLLRLLRRLRRLLRRRRLLLLRRRLRLRRLLLRRLLLRLLLRRLRRLRRRLLRLRRLRRLLLRLRLLRLRRLLRRRRRLRRRLRRLRLLRLLLLLLLRLLRLLLRRRRLRRLRLLLRRRLRLLRRLRLLRLRLRLLLRRLLLLRLRRRLLLLLLRRLLRLLLRRLRRRRRLLLRLRRLRLLLLRLLLRLLLRRRRLRLRRLRLLLLRLRLRLRLRLLRLLLLLLRRRLLLLLRRLLLLRLLLLR...

output:

831921527 841981814 841981814 0 802033891 802033891 0 0 0 0 0 0 0 0 313870399 313870399 0 0 0 845084145 845084145 0 202490903 202490903 292802290 292802290 0 0 0 0 246685715 246685715 0 0 750008183 750008183 0 0 0 627041700 627041700 0 129985167 129985167 0 414419357 414419357 0 0 0 0 0 0 0 69839104...

result:

ok single line: '831921527 841981814 841981814 ...9451543 0 0 73252857 73252857 0'

Test #11:

score: 0
Accepted
time: 506ms
memory: 30488kb

input:

1000
RRLRRLRLRLLRRRLRLRLRLLLRLLLRLRLLRLRRRLRRRRLLRLLLLRLLRLLRLRLRLLLLRRRRRLRLLLRLLRLRRLRLLLRRLLLLLRLRRRRLRRRLLLLRRLRLLLLLRRRRLLRLRLRLLRRRRRLLRRLRLRLLLLRRRRRLRRLLRRRLRRRRLRLLRRLLRRRLLLLRLLLLRRRRLRLLLLLRRRRLLLRLLRLRLRLRLRLRLRRLLLLRRRLRLLLRLLRRLRRRLLLLLLLLLLLRLLLLLLLRLLLRLRRLRLLLRLLRLLLLRLRLRLRLLRLRLLR...

output:

511795335 0 69779310 69779310 0 739828205 739828205 753376067 753376067 0 701671563 701671563 0 0 212012731 212012731 878780187 878780187 579239850 579239850 0 0 522816863 522816863 0 0 334242623 334242623 863711626 863711626 0 643092447 643092447 851181131 851181131 0 0 561587102 561587102 0 0 0 0 ...

result:

ok single line: '511795335 0 69779310 69779310 ...0 186342784 186342784 663982717'

Test #12:

score: -100
Time Limit Exceeded

input:

100000
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL...

output:


result: