結果

問題 No.2513 Power Eraser
ユーザー 👑 kmjpkmjp
提出日時 2023-10-26 01:00:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 4,910 bytes
コンパイル時間 3,334 ms
コンパイル使用メモリ 230,596 KB
実行使用メモリ 84,412 KB
最終ジャッジ日時 2023-10-26 01:01:11
合計ジャッジ時間 22,917 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
80,924 KB
testcase_01 AC 5 ms
14,572 KB
testcase_02 AC 4 ms
14,580 KB
testcase_03 AC 18 ms
15,048 KB
testcase_04 AC 111 ms
16,792 KB
testcase_05 AC 24 ms
15,164 KB
testcase_06 AC 177 ms
17,908 KB
testcase_07 AC 74 ms
16,376 KB
testcase_08 AC 125 ms
17,176 KB
testcase_09 AC 203 ms
18,144 KB
testcase_10 AC 123 ms
17,020 KB
testcase_11 AC 22 ms
15,120 KB
testcase_12 AC 104 ms
16,692 KB
testcase_13 AC 2,915 ms
49,716 KB
testcase_14 TLE -
testcase_15 TLE -
testcase_16 AC 3,633 ms
54,232 KB
testcase_17 AC 4,347 ms
60,776 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
7_evil_case_1.txt -- -
7_evil_case_2.txt -- -
7_evil_case_3.txt -- -
7_evil_case_4.txt -- -
7_evil_case_5.txt -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
ll A[202020];
const ll mo=998244353;

ll modpow(ll a, ll n = mo-2) {
	ll r=1; a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

template <class T> using vec=vector<T>; //using vec=valarray<T>;

template<class T> vec<T> fft(vec<T> v, bool rev=false) {
	int n=v.size(),i,j,m;
	for(int m=n; m>=2; m/=2) {
		T wn=modpow(5,(mo-1)/m);
		if(rev) wn=modpow(wn);
		for(i=0;i<n;i+=m) {
			T w=1;
			for(int j1=i,j2=i+m/2;j2<i+m;j1++,j2++) {
				T t1=v[j1],t2=v[j2];
				v[j1]=t1+t2;
				v[j2]=ll(t1+mo-t2)*w%mo;
				while(v[j1]>=mo) v[j1]-=mo;
				w=(ll)w*wn%mo;
			}
		}
	}
	for(i=0,j=1;j<n-1;j++) {
		for(int k=n>>1;k>(i^=k);k>>=1);
		if(i>j) swap(v[i],v[j]);
	}
	if(rev) {
		ll rv = modpow(n);
		FOR(i,n) v[i]=(ll)v[i]*rv%mo;
	}
	return v;
}

template<class T> vec<T> MultPoly(vec<T> P,vec<T> Q,bool resize=false) {
	if(resize) {
		int maxind=0,pi=0,qi=0,i;
		int s=2;
		FOR(i,P.size()) if(norm(P[i])) pi=i;
		FOR(i,Q.size()) if(norm(Q[i])) qi=i;
		maxind=pi+qi+1;
		while(s*2<maxind) s*=2;
		
		if(s<=16) { //fastpath
			vec<T> R(s*2);
			for(int x=0;x<=pi;x++) for(int y=0;y<=qi;y++) (R[x+y]+=P[x]*Q[y])%=mo;
			return R;
		}
		vec<T> P2(s*2),Q2(s*2);
		FOR(i,pi+1) P2[i]=P[i];
		FOR(i,qi+1) Q2[i]=Q[i];
		swap(P,P2),swap(Q,Q2);
	}
	P=fft(P), Q=fft(Q);
	for(int i=0;i<P.size();i++) P[i]=(ll)P[i]*Q[i]%mo;
	return fft(P,true);
}


template<class T> vec<T> inverse(vec<T> a,int tsize=-1) { 
	assert(a[0]>0);
	if(tsize==-1) tsize=a.size();
	vec<T> b={(T)modpow(a[0])};
	while(b.size()<tsize) {
		vec<T> c(a.begin(),a.begin()+min(tsize,2*(int)b.size()));
		vec<T> d=MultPoly(b,b,true);
		if(d.size()>tsize) d.resize(tsize);
		c = MultPoly(c,d,true);
		b.resize(2*b.size());
		int i;
		for(i=b.size()/2;i<b.size();i++) b[i]=(mo-c[i])%mo;
	}
	b.resize(tsize);
	return b;
}

template<class T> vec<T> SubPoly(vec<T> P,vec<T> Q) {
	if(P.size()<Q.size()) P.resize(Q.size());
	for(int i=0;i<Q.size();i++) {
		P[i]-=Q[i];
		if(P[i]<0) P[i]+=mo;
	}
	return P;
}

template<class T> pair<vec<T>,vec<T>> divmod(vec<T> a,vec<T> b) { //多項式除算。FPSには使えない。
	//最高次数で反転する
	int A=-1,B=-1,i;
	FOR(i,a.size()) if(a[i]) A=i;
	FOR(i,b.size()) if(b[i]) B=i;
	assert(B>=0);
	if(A<B) return make_pair(vector<ll>({0LL}),a);
	a.resize(A+1);
	b.resize(B+1);
	reverse(ALL(a));
	reverse(ALL(b));
	
	
	b.resize(A+1);
	auto rb=inverse(b,A-B+1); // 1/b
	auto a2=a;
	a2.resize(A-B+1);
	auto c=MultPoly(a2,rb,1); // c=a/b
	c.resize(A-B+1);
	reverse(ALL(c));
	
	b.resize(B+1);
	reverse(ALL(b));
	auto bc=MultPoly(c,b,1); //bc=a/b*b
	bc.resize(A+1);
	reverse(ALL(a));
	auto r=SubPoly(a,bc); // r=a-bc
	r.resize(B);
	return make_pair(c,r);
}

map<int,vector<ll>> memo[202020];
vector<ll> get(int L,int R) {
	if(memo[L].count(R)==0) {
		vector<ll> V;
		if(L+1==R) {
			if(L>=N) V={1};
			else V={A[L],mo-1};
		}
		else {
			V=MultPoly(get(L,(R+L)/2),get((R+L)/2,R),1);
		}
		memo[L][R]=V;
	}
	return memo[L][R];
}

vec<ll> multipoint_evaluation(vec<ll> f,vec<ll> m) { //mをソートする点に注意
	//sort(ALL(m));
	int ON=m.size();
	//2の累乗にする
	while(m.size()&(m.size()-1)) m.push_back(m.back()+1);
	int i,N=m.size();
	vec<vec<ll>> Xs(2*N),Rs(2*N),LL(2*N),RR(2*N);
	FOR(i,N) {
		if(i<ON) Xs[N+i]={m[i],mo-1};
		else Xs[N+i]={1};
	}
	for(i=N-1;i>=1;i--) Xs[i]=MultPoly(Xs[i*2],Xs[i*2+1],1);
	Rs[1]=divmod(f,Xs[1]).second;
	for(i=2;i<2*N;i++) {
		if(Xs[i].size()==1) {
			Rs[i].clear();
		}
		else {
			Rs[i]=divmod(Rs[i/2],Xs[i]).second;
			Rs[i].resize(Xs[i].size()-1);
		}
	}
	
	vec<ll> ret;
	FOR(i,N) ret.push_back(Rs[N+i].empty()?0:Rs[N+i][0]);
	return ret;
}



ll hoge(int L,int R,int D) {
	int m=1;
	while(m<D) m*=2;
	int i;
	vector<ll> F=get(L,R),M;

	for(i=R;i<R+D;i++) M.push_back(A[i]);
	auto a=multipoint_evaluation(F,M);
	ll ret=1;
	FOR(i,D) ret=ret*a[i]%mo;
	return ret;
}

ll dfs(int L,int R) {
	if(R-L<=1) return 1;
	ll ret=1;
	int M=(L+R)/2;
	ret=ret*dfs(L,M)%mo*dfs(M,R)%mo;
	ret=ret*hoge(L,M,R-M)%mo;
	return ret;
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>A[i];
	ll ret=1;
	
	ret=dfs(0,N);
	
	cout<<(ret%mo+mo)%mo<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0