結果

問題 No.206 数の積集合を求めるクエリ
ユーザー tentententen
提出日時 2023-06-13 11:38:01
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,468 bytes
コンパイル時間 2,764 ms
コンパイル使用メモリ 84,760 KB
実行使用メモリ 65,272 KB
最終ジャッジ日時 2023-09-03 18:51:37
合計ジャッジ時間 30,820 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
50,616 KB
testcase_01 AC 59 ms
51,140 KB
testcase_02 AC 60 ms
50,548 KB
testcase_03 AC 59 ms
48,888 KB
testcase_04 AC 60 ms
50,640 KB
testcase_05 AC 62 ms
50,676 KB
testcase_06 AC 81 ms
52,996 KB
testcase_07 AC 82 ms
51,488 KB
testcase_08 AC 82 ms
53,076 KB
testcase_09 AC 83 ms
52,992 KB
testcase_10 AC 59 ms
50,748 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 309 ms
57,392 KB
testcase_18 AC 229 ms
57,516 KB
testcase_19 AC 294 ms
57,468 KB
testcase_20 AC 229 ms
57,252 KB
testcase_21 AC 263 ms
57,720 KB
testcase_22 AC 252 ms
57,776 KB
testcase_23 AC 303 ms
57,512 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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(bs.values[diff + i] & 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;
                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();
    }
    
}
0