結果

問題 No.206 数の積集合を求めるクエリ
ユーザー kotatsugamekotatsugame
提出日時 2019-09-26 18:14:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 242 ms / 7,000 ms
コード長 1,432 bytes
コンパイル時間 493 ms
コンパイル使用メモリ 52,872 KB
実行使用メモリ 8,512 KB
最終ジャッジ日時 2023-10-24 15:38:08
合計ジャッジ時間 5,131 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 8 ms
4,348 KB
testcase_07 AC 8 ms
4,348 KB
testcase_08 AC 8 ms
4,348 KB
testcase_09 AC 8 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 8 ms
4,348 KB
testcase_13 AC 8 ms
4,348 KB
testcase_14 AC 8 ms
4,348 KB
testcase_15 AC 8 ms
4,348 KB
testcase_16 AC 9 ms
4,348 KB
testcase_17 AC 233 ms
8,512 KB
testcase_18 AC 221 ms
8,512 KB
testcase_19 AC 230 ms
8,512 KB
testcase_20 AC 221 ms
8,512 KB
testcase_21 AC 225 ms
8,512 KB
testcase_22 AC 224 ms
8,512 KB
testcase_23 AC 231 ms
8,512 KB
testcase_24 AC 242 ms
8,512 KB
testcase_25 AC 239 ms
8,512 KB
testcase_26 AC 231 ms
8,512 KB
testcase_27 AC 225 ms
8,512 KB
testcase_28 AC 234 ms
8,512 KB
testcase_29 AC 233 ms
8,512 KB
testcase_30 AC 231 ms
8,512 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:59:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   59 | main()
      | ^~~~

ソースコード

diff #

#include<cstdio>
using namespace std;
//998244353,3
#include<vector>
template<int mod,int proot>
struct NTT{
	long long power(long long a,int b)
	{
		long long ret=1;
		while(b)
		{
			if(b&1)ret=ret*a%mod;
			a=a*a%mod;
			b>>=1;
		}
		return ret;
	}
	void dft(vector<int>&A,bool sign)
	{
		int N=A.size()>>1;
		if(N==0)return;
		vector<int>F(N),G(N);
		for(int i=0;i<N;i++)
		{
			F[i]=A[i<<1];
			G[i]=A[i<<1|1];
		}
		dft(F,sign);
		dft(G,sign);
		long long z=power(proot,sign?(long long)(mod-1)/N/2*(mod-2)%(mod-1):(mod-1)/N/2),p=1;
		for(int i=0;i<N;i++)
		{
			A[i]=(F[i]+p*G[i])%mod;
			A[i+N]=(F[i]-p*G[i])%mod;
			if(A[i+N]<0)A[i+N]+=mod;
			(p*=z)%=mod;
		}
	}
	vector<int>multiply(vector<int>A,vector<int>B)
	{
		if(A.empty()||B.empty())
		{
			return(vector<int>){};
		}
		int N=1;
		vector<int>ret(A.size()+B.size()-1);
		while(N<ret.size())N<<=1;
		A.resize(N);
		B.resize(N);
		dft(A,false);
		dft(B,false);
		for(int i=0;i<N;i++)A[i]=(long long)A[i]*B[i]%mod;
		dft(A,true);
		long long invN=power(N,mod-2);
		for(int i=0;i<ret.size();i++)ret[i]=invN*A[i]%mod;
		return ret;
	}
};
main()
{
	int L,M,N;
	scanf("%d%d%d",&L,&M,&N);
	vector<int>A(N+1),B(N+1);
	for(int i=0;i<L;i++)
	{
		int a;scanf("%d",&a);
		A[a]=1;
	}
	for(int i=0;i<M;i++)
	{
		int a;scanf("%d",&a);
		B[N-a]=1;
	}
	NTT<998244353,3>ntt;
	vector<int>C=ntt.multiply(A,B);
	int Q;scanf("%d",&Q);
	for(int i=0;i<Q;i++)
	{
		printf("%d\n",C[N+i]);
	}
}
0