結果

問題 No.206 数の積集合を求めるクエリ
ユーザー GrenacheGrenache
提出日時 2015-06-08 15:51:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,687 ms / 7,000 ms
コード長 3,159 bytes
コンパイル時間 4,104 ms
コンパイル使用メモリ 74,640 KB
実行使用メモリ 60,388 KB
最終ジャッジ日時 2023-09-20 19:53:06
合計ジャッジ時間 12,921 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,600 KB
testcase_01 AC 45 ms
49,464 KB
testcase_02 AC 43 ms
49,316 KB
testcase_03 AC 43 ms
49,320 KB
testcase_04 AC 44 ms
49,720 KB
testcase_05 AC 44 ms
49,488 KB
testcase_06 AC 65 ms
51,536 KB
testcase_07 AC 67 ms
52,440 KB
testcase_08 AC 80 ms
53,020 KB
testcase_09 AC 82 ms
53,008 KB
testcase_10 AC 44 ms
49,420 KB
testcase_11 AC 47 ms
49,512 KB
testcase_12 AC 110 ms
52,980 KB
testcase_13 AC 108 ms
53,548 KB
testcase_14 AC 99 ms
52,760 KB
testcase_15 AC 95 ms
51,940 KB
testcase_16 AC 103 ms
52,824 KB
testcase_17 AC 180 ms
53,876 KB
testcase_18 AC 149 ms
51,968 KB
testcase_19 AC 182 ms
54,272 KB
testcase_20 AC 142 ms
53,588 KB
testcase_21 AC 169 ms
53,688 KB
testcase_22 AC 162 ms
53,972 KB
testcase_23 AC 185 ms
53,704 KB
testcase_24 AC 917 ms
58,996 KB
testcase_25 AC 1,105 ms
57,056 KB
testcase_26 AC 1,687 ms
58,780 KB
testcase_27 AC 862 ms
59,052 KB
testcase_28 AC 1,150 ms
60,388 KB
testcase_29 AC 1,554 ms
58,976 KB
testcase_30 AC 1,066 ms
58,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.InputMismatchException;


public class Main_yukicoder206 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Printer pr = new Printer(System.out);

		int l = sc.nextInt();
		int m = sc.nextInt();
		int n = sc.nextInt();

		long[] a = new long[(2 * n + 63) / 64];
		long[] b = new long[(2 * n + 63) / 64];
		for (int i = 0; i < l; i++) {
			setBit(a, sc.nextInt() - 1);
		}
		for (int i = 0; i < m; i++) {
			setBit(b, sc.nextInt() - 1);
		}

		int q = sc.nextInt();
		for (int i = 0; i < q; i++) {
			pr.println(countBit(a, b));
			shiftBit(b);
		}
		
		pr.close();
		sc.close();
	}

	private static void shiftBit(long[] b) {
		boolean carry = false;
		for (int i = 0; i < b.length; i++) {
			boolean tmp = (b[i] & 0x8000000000000000L) != 0;
			b[i] <<= 1;
			if (carry) {
				b[i] |= 0x1L;
			}
			carry = tmp;
		}
		
	}

	private static int countBit(long[] a, long[] b) {
		int ret = 0;
		for (int i = 0; i < a.length; i++) {
			long tmp = a[i] & b[i];
			ret += Long.bitCount(tmp);
		}

		return ret;
	}

	private static void setBit(long[] a, int i) {
		int n = i / 64;
		long mask = 0x1L << (i % 64);
		a[n] |= mask;

	}

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		StreamTokenizer st;
		
		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
			st = new StreamTokenizer(br);
		}
		
		String next() throws RuntimeException  {
			try {
				if (st.nextToken() != StreamTokenizer.TT_WORD) {
					throw new InputMismatchException();
				}
			
				return st.sval;

			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}
		
		int nextInt() throws RuntimeException {
			try {
				if (st.nextToken() != StreamTokenizer.TT_NUMBER) {
					throw new InputMismatchException();
				}

				return (int)st.nval;
			
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}

		long nextLong() throws RuntimeException {
			try {
				if (st.nextToken() != StreamTokenizer.TT_NUMBER) {
					throw new InputMismatchException();
				}

				return (long)st.nval;
			
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}

		float nextFloat() throws RuntimeException {
			try {
				if (st.nextToken() != StreamTokenizer.TT_NUMBER) {
					throw new InputMismatchException();
				}

				return (float)st.nval;
			
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}

		double nextDouble() throws RuntimeException {
			try {
				if (st.nextToken() != StreamTokenizer.TT_NUMBER) {
					throw new InputMismatchException();
				}

				return st.nval;
			
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0