結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー 👑 kmjpkmjp
提出日時 2020-05-30 00:24:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,437 ms / 3,500 ms
コード長 2,040 bytes
コンパイル時間 2,371 ms
コンパイル使用メモリ 208,128 KB
実行使用メモリ 24,180 KB
最終ジャッジ日時 2024-04-24 03:01:13
合計ジャッジ時間 46,577 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 36 ms
6,944 KB
testcase_04 AC 27 ms
6,940 KB
testcase_05 AC 29 ms
6,940 KB
testcase_06 AC 22 ms
6,940 KB
testcase_07 AC 20 ms
6,944 KB
testcase_08 AC 29 ms
6,940 KB
testcase_09 AC 33 ms
6,940 KB
testcase_10 AC 14 ms
6,940 KB
testcase_11 AC 20 ms
6,944 KB
testcase_12 AC 12 ms
6,940 KB
testcase_13 AC 2,341 ms
24,052 KB
testcase_14 AC 2,365 ms
24,048 KB
testcase_15 AC 2,364 ms
24,048 KB
testcase_16 AC 2,346 ms
24,048 KB
testcase_17 AC 2,354 ms
24,048 KB
testcase_18 AC 2,349 ms
24,044 KB
testcase_19 AC 2,350 ms
24,052 KB
testcase_20 AC 2,347 ms
24,108 KB
testcase_21 AC 2,334 ms
24,044 KB
testcase_22 AC 2,328 ms
24,048 KB
testcase_23 AC 2,354 ms
23,968 KB
testcase_24 AC 2,437 ms
24,180 KB
testcase_25 AC 2,396 ms
24,048 KB
testcase_26 AC 2,370 ms
24,048 KB
testcase_27 AC 2,384 ms
24,176 KB
testcase_28 AC 2,171 ms
24,172 KB
testcase_29 AC 2,130 ms
24,156 KB
testcase_30 AC 2,127 ms
24,048 KB
testcase_31 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#undef _P
#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 ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

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

ll modpow(ll a, ll n = mo-2) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}
vector<ll> fft(vector<ll> v, bool rev=false) {
	int n=v.size(),i,j,m;
	
	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]);
	}
	for(int m=2; m<=n; m*=2) {
		ll wn=modpow(5,(mo-1)/m);
		if(rev) wn=modpow(wn);
		for(i=0;i<n;i+=m) {
			ll w=1;
			for(int j1=i,j2=i+m/2;j2<i+m;j1++,j2++) {
				ll t1=v[j1],t2=w*v[j2]%mo;
				v[j1]=t1+t2;
				v[j2]=t1+mo-t2;
				while(v[j1]>=mo) v[j1]-=mo;
				while(v[j2]>=mo) v[j2]-=mo;
				w=w*wn%mo;
			}
		}
	}
	if(rev) {
		ll rv = modpow(n);
		FOR(i,n) v[i]=v[i]*rv%mo;
	}
	return v;
}

vector<ll> MultPoly(vector<ll> P,vector<ll> 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;
		P.resize(s*2);Q.resize(s*2);
	}
	P=fft(P), Q=fft(Q);
	for(int i=0;i<P.size();i++) P[i]=P[i]*Q[i]%mo;
	return fft(P,true);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>Q;
	deque<vector<ll>> V;
	FOR(i,N) {
		cin>>A[i];
		V.push_back({(A[i]-1)%mo,1});
	}
	
	while(V.size()>=2) {
		V.push_back(MultPoly(V[0],V[1],true));
		V.pop_front();
		V.pop_front();
	}
	
	FOR(i,Q) {
		cin>>x;
		cout<<V[0][x]<<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