結果
問題 | No.206 数の積集合を求めるクエリ |
ユーザー | tenten |
提出日時 | 2023-06-13 11:41:00 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 6,667 ms / 7,000 ms |
コード長 | 3,502 bytes |
コンパイル時間 | 3,066 ms |
コンパイル使用メモリ | 90,228 KB |
実行使用メモリ | 63,880 KB |
最終ジャッジ日時 | 2024-06-13 00:02:19 |
合計ジャッジ時間 | 45,347 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 66 ms
50,856 KB |
testcase_01 | AC | 66 ms
51,260 KB |
testcase_02 | AC | 65 ms
50,776 KB |
testcase_03 | AC | 65 ms
51,092 KB |
testcase_04 | AC | 66 ms
51,060 KB |
testcase_05 | AC | 68 ms
51,408 KB |
testcase_06 | AC | 94 ms
51,932 KB |
testcase_07 | AC | 94 ms
51,780 KB |
testcase_08 | AC | 96 ms
51,700 KB |
testcase_09 | AC | 94 ms
52,088 KB |
testcase_10 | AC | 66 ms
51,136 KB |
testcase_11 | AC | 69 ms
51,104 KB |
testcase_12 | AC | 125 ms
52,568 KB |
testcase_13 | AC | 109 ms
52,024 KB |
testcase_14 | AC | 112 ms
52,440 KB |
testcase_15 | AC | 106 ms
52,096 KB |
testcase_16 | AC | 105 ms
52,256 KB |
testcase_17 | AC | 294 ms
56,580 KB |
testcase_18 | AC | 234 ms
56,300 KB |
testcase_19 | AC | 280 ms
56,524 KB |
testcase_20 | AC | 213 ms
56,088 KB |
testcase_21 | AC | 258 ms
56,968 KB |
testcase_22 | AC | 258 ms
56,932 KB |
testcase_23 | AC | 288 ms
56,760 KB |
testcase_24 | AC | 6,363 ms
61,080 KB |
testcase_25 | AC | 6,299 ms
63,880 KB |
testcase_26 | AC | 6,667 ms
59,152 KB |
testcase_27 | AC | 3,040 ms
58,344 KB |
testcase_28 | AC | 5,598 ms
61,624 KB |
testcase_29 | AC | 6,042 ms
61,224 KB |
testcase_30 | AC | 3,259 ms
62,528 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int l = sc.nextInt(); int m = sc.nextInt(); int n = sc.nextInt(); BitSet.length = n + 1; BitSet base = new BitSet(); for (int i = 0; i < l; i++) { base.add(sc.nextInt()); } BitSet target = new BitSet(); for (int i = 0; i < m; i++) { target.add(sc.nextInt()); } int q = sc.nextInt(); int[] ans = new int[q]; for (int i = 0; i < 60 && i < q; i++) { for (int j = 0; j < (q + 59) / 60; j++) { if (j * 60 + i >= q) { break; } ans[j * 60 + i] = base.getCount(j, target); } target.shift(); } System.out.println(String.join("\n", Arrays.stream(ans).mapToObj(String::valueOf).toArray(String[]::new))); } static class BitSet { static int length; int size; long[] values; static final long MASK = (1L << 60) - 1; public BitSet() { size = (length + 59) / 60; values = new long[size]; } public void add(int x) { values[x / 60] |= (1L << (x % 60)); } public int getCount(int diff, BitSet bs) { int count = 0; for (int i = 0; i + diff < size; i++) { count += getPop(values[diff + i] & bs.values[i]); } return count; } private int getPop(long x) { long pop = 0; while (x > 0) { pop += x % 2; x >>= 1; } return (int)pop; } public void shift() { long add = 0; for (int i = 0; i < size; i++) { values[i] <<= 1; values[i] += add; if ((values[i] & (1L << 60)) == 0) { add = 0; } else { values[i] ^= (1L << 60); add = 1; } } } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }