結果

問題 No.206 数の積集合を求めるクエリ
ユーザー furuya1223furuya1223
提出日時 2017-08-27 18:14:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 299 ms / 7,000 ms
コード長 3,033 bytes
コンパイル時間 1,855 ms
コンパイル使用メモリ 172,688 KB
実行使用メモリ 30,712 KB
最終ジャッジ日時 2024-04-24 00:23:47
合計ジャッジ時間 6,393 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 7 ms
5,376 KB
testcase_13 AC 7 ms
5,376 KB
testcase_14 AC 7 ms
5,376 KB
testcase_15 AC 7 ms
5,376 KB
testcase_16 AC 7 ms
5,376 KB
testcase_17 AC 140 ms
17,408 KB
testcase_18 AC 123 ms
17,520 KB
testcase_19 AC 128 ms
17,516 KB
testcase_20 AC 122 ms
17,516 KB
testcase_21 AC 128 ms
17,396 KB
testcase_22 AC 126 ms
17,392 KB
testcase_23 AC 130 ms
17,396 KB
testcase_24 AC 299 ms
30,464 KB
testcase_25 AC 295 ms
30,464 KB
testcase_26 AC 287 ms
30,712 KB
testcase_27 AC 289 ms
30,248 KB
testcase_28 AC 285 ms
30,460 KB
testcase_29 AC 280 ms
30,588 KB
testcase_30 AC 279 ms
30,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS (1e-8)
#define MOD 1000000007
#define PI 3.141592653589793
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef complex<double> comp;
typedef vector<complex<double>> vcomp;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
//*
// シンプルな構文解析用
typedef string::const_iterator State;
class ParseError {};
//*/
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

vector<complex<double>> fft(vector<complex<double>> a, bool rev = false) {
	int n = a.size();
	int h = 0;
	for (int i = 0; 1 << i < n; i++) h++;
	for (int i = 0; i < n; i++) {
		int j = 0;
		for (int k = 0; k < h; k++) j |= (i >> k & 1) << (h - 1 - k);
		if (i < j) swap(a[i], a[j]);
	}
	for (int i = 1; i < n; i *= 2) {
		for (int j = 0; j < i; j++) {
			complex<double> w = polar(1.0, 2 * PI / (i * 2) * (rev ? -1 : 1) * j);
			for (int k = 0; k < n; k += i * 2) {
				complex<double> s = a[j + k + 0];
				complex<double> t = a[j + k + i] * w;
				a[j + k + 0] = s + t;
				a[j + k + i] = s - t;
			}
		}
	}
	if (rev) for (int i = 0; i < n; i++) a[i] /= n;
	return a;
}

vector<int> mul(vector<int> a, vector<int> b) {
	int s = a.size() + b.size() - 1;
	int t = 1;
	while (t < s) t *= 2;
	vector<complex<double>> A(t), B(t);
	for (int i = 0; i < a.size(); i++) A[i].real(a[i]);
	for (int i = 0; i < b.size(); i++) B[i].real(b[i]);
	A = fft(A);
	B = fft(B);
	for (int i = 0; i < t; i++) A[i] *= B[i];
	A = fft(A, true);
	a.resize(s);
	for (int i = 0; i < s; i++) a[i] = round(A[i].real());
	return a;
}

int main() {
	int L, M, N;
	cin >> L >> M >> N;

	vector<int> a(N + 1, 0), b(N + 1, 0);

	for (int i = 1; i <= L; i++) {
		int na;
		scanf("%d", &na);
		na--;
		a[na] = 1;
	}
	for (int i = 1; i <= M; i++) {
		int nb;
		scanf("%d", &nb);
		nb--;
		b[N - 1 - nb] = 1;
	}

	int Q;
	cin >> Q;

	a.resize(N + Q);

	a = mul(a, b);

	for (int i = N - 1; i < N - 1 + Q; i++) {
		printf("%d\n", a[i]);
	}
}
0