結果
問題 | No.206 数の積集合を求めるクエリ |
ユーザー | eitaho |
提出日時 | 2016-11-23 03:35:15 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 346 ms / 7,000 ms |
コード長 | 4,431 bytes |
コンパイル時間 | 1,051 ms |
コンパイル使用メモリ | 110,976 KB |
実行使用メモリ | 42,368 KB |
最終ジャッジ日時 | 2024-11-27 09:47:09 |
合計ジャッジ時間 | 7,078 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
19,072 KB |
testcase_01 | AC | 25 ms
18,944 KB |
testcase_02 | AC | 25 ms
19,072 KB |
testcase_03 | AC | 25 ms
18,816 KB |
testcase_04 | AC | 26 ms
18,816 KB |
testcase_05 | AC | 25 ms
18,816 KB |
testcase_06 | AC | 36 ms
19,712 KB |
testcase_07 | AC | 36 ms
19,712 KB |
testcase_08 | AC | 36 ms
19,712 KB |
testcase_09 | AC | 36 ms
19,712 KB |
testcase_10 | AC | 26 ms
19,072 KB |
testcase_11 | AC | 24 ms
19,072 KB |
testcase_12 | AC | 34 ms
20,352 KB |
testcase_13 | AC | 35 ms
19,968 KB |
testcase_14 | AC | 37 ms
20,224 KB |
testcase_15 | AC | 39 ms
19,968 KB |
testcase_16 | AC | 39 ms
20,096 KB |
testcase_17 | AC | 303 ms
39,936 KB |
testcase_18 | AC | 318 ms
30,464 KB |
testcase_19 | AC | 338 ms
39,424 KB |
testcase_20 | AC | 263 ms
30,976 KB |
testcase_21 | AC | 299 ms
33,024 KB |
testcase_22 | AC | 275 ms
32,640 KB |
testcase_23 | AC | 333 ms
39,424 KB |
testcase_24 | AC | 324 ms
42,368 KB |
testcase_25 | AC | 342 ms
40,704 KB |
testcase_26 | AC | 339 ms
37,376 KB |
testcase_27 | AC | 331 ms
35,456 KB |
testcase_28 | AC | 329 ms
39,808 KB |
testcase_29 | AC | 346 ms
39,936 KB |
testcase_30 | AC | 313 ms
36,480 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Collections.Generic; using System.Diagnostics; using System.Numerics; using Enu = System.Linq.Enumerable; public class Program { public void Solve() { int L = Reader.Int(), M = Reader.Int(), N = Reader.Int(); var A = Reader.IntArray(L); var B = Reader.IntArray(M); int Q = Reader.Int(); var X = new int[N + 1]; var Y = new int[N + 1]; foreach (int a in A) X[a] = 1; foreach (int b in B) Y[N - b] = 1; var res = new FFTMod().Mult(X, Y); Console.WriteLine(string.Join("\n", res.Skip(N).Take(Q))); } } class FFTMod { int Mod, PrimitiveRoot; public long[] Mult(int[] A, int[] B) { return Mult(A, B, 167772161, 3); } public long[] Mult(int[] A, int[] B, int mod, int primitiveRoot) { Mod = mod; PrimitiveRoot = primitiveRoot; int N = A.Length + B.Length - 1; int N2 = N; while ((N2 & N2 - 1) != 0) N2 += N2 & -N2; long[] a = new long[N2], b = new long[N2]; for (int i = 0; i < A.Length; i++) a[i] = A[i]; for (int i = 0; i < B.Length; i++) b[i] = B[i]; Transform(a); Transform(b); for (int i = 0; i < N2; i++) a[i] = a[i] * b[i] % Mod; Transform(a, true); long inv = Power(N2, Mod - 2); for (int i = 0; i < N2; i++) a[i] = a[i] * inv % mod; return a; } void Transform(long[] A, bool inv = false) { int N = A.Length; long H = Power(PrimitiveRoot, (Mod - 1) / N); if (inv) H = Power(H, Mod - 2); for (int a = 0, b = 0; b < N; ++b) { if (b < a) { var t = A[a]; A[a] = A[b]; A[b] = t; } for (int k = N >> 1; k > (a ^= k); k >>= 1) { } } for (int m = 1; m < N; m <<= 1) { int m2 = m << 1; long b = Power(H, N / m2); long w = 1; for (int a = 0; a < m; ++a, w = w * b % Mod) for (int k = a; k < N; k += m2) { long x = A[k]; long y = A[k + m] * w % Mod; long tx = x + y; long ty = x - y; A[k] = tx >= Mod ? tx - Mod : tx; A[k + m] = ty < 0 ? ty + Mod : ty; } } } long Power(long x, long n) { long res = 1; if ((x %= Mod) < 0) x += Mod; for (; n > 0; n >>= 1, x = x * x % Mod) if ((n & 1) == 1) res = res * x % Mod; return res; } } class Entry { static void Main() { new Program().Solve(); } } class Reader { static TextReader reader = Console.In; static readonly char[] separator = { ' ' }; static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries; static string[] A = new string[0]; static int i; static void Init() { A = new string[0]; } public static void Set(TextReader r) { reader = r; Init(); } public static void Set(string file) { reader = new StreamReader(file); Init(); } public static bool HasNext() { return CheckNext(); } public static string String() { return Next(); } public static int Int() { return int.Parse(Next()); } public static long Long() { return long.Parse(Next()); } public static double Double() { return double.Parse(Next()); } public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); } public static int[] IntArray(int N) { return Range(N, Int); } public static int[][] IntTable(int H) { return Range(H, IntLine); } public static string[] StringArray(int N) { return Range(N, Next); } public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); } public static string Line() { return reader.ReadLine().Trim(); } public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; } static string[] Split(string s) { return s.Split(separator, op); } static string Next() { CheckNext(); return A[i++]; } static bool CheckNext() { if (i < A.Length) return true; string line = reader.ReadLine(); if (line == null) return false; if (line == "") return CheckNext(); A = Split(line); i = 0; return true; } }