結果

問題 No.206 数の積集合を求めるクエリ
ユーザー tentententen
提出日時 2023-01-27 09:26:08
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 3,102 bytes
コンパイル時間 2,821 ms
コンパイル使用メモリ 85,928 KB
実行使用メモリ 62,324 KB
最終ジャッジ日時 2023-09-10 05:57:52
合計ジャッジ時間 15,261 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,436 KB
testcase_01 AC 46 ms
49,932 KB
testcase_02 AC 45 ms
49,496 KB
testcase_03 AC 45 ms
49,920 KB
testcase_04 AC 43 ms
47,388 KB
testcase_05 AC 45 ms
49,436 KB
testcase_06 AC 63 ms
51,324 KB
testcase_07 AC 73 ms
50,448 KB
testcase_08 AC 78 ms
50,792 KB
testcase_09 AC 69 ms
51,668 KB
testcase_10 AC 46 ms
49,376 KB
testcase_11 AC 47 ms
49,312 KB
testcase_12 AC 114 ms
52,436 KB
testcase_13 AC 100 ms
50,432 KB
testcase_14 AC 96 ms
52,268 KB
testcase_15 AC 103 ms
52,028 KB
testcase_16 AC 93 ms
51,652 KB
testcase_17 AC 251 ms
56,292 KB
testcase_18 AC 196 ms
55,548 KB
testcase_19 AC 269 ms
56,512 KB
testcase_20 AC 207 ms
55,408 KB
testcase_21 AC 218 ms
56,552 KB
testcase_22 AC 210 ms
56,316 KB
testcase_23 AC 247 ms
55,848 KB
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 AC 3,866 ms
57,884 KB
testcase_28 AC 6,534 ms
57,732 KB
testcase_29 TLE -
testcase_30 AC 4,152 ms
57,808 KB
権限があれば一括ダウンロードができます

ソースコード

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();
        BitArray a = new BitArray(n);
        for (int i = 0; i < l; i++) {
            a.setBit(sc.nextInt() - 1);
        }
        BitArray b = new BitArray(n);
        for (int i = 0; i < m; i++) {
            b.setBit(sc.nextInt() - 1);
        }
        int q = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            sb.append(a.getAndCount(b)).append("\n");
            a.shift();
        }
        System.out.print(sb);
    }
    
    static class BitArray {
        int[] arr;
        int size;
        
        public BitArray(int x) {
            size = (x + 30 - 1) / 30;
            arr = new int[size];
        }
        
        public BitArray(int size, int[] arr) {
            this.size = size;
            this.arr = arr;
        }
        
        public void setBit(int x) {
            arr[x / 30] |= (1L << (x % 30));
        }
        
        public void shift() {
            int add = 0;
            for (int i = size - 1; i >= 0; i--) {
                arr[i] += (add << 30);
                add = arr[i] % 2;
                arr[i] >>= 1;
            }
        }
        
        public int getAndCount(BitArray x) {
            int count = 0;
            for (int i = 0; i < size; i++) {
                count += pitCount(arr[i] & x.arr[i]);
            }
            return count;
        }
        
        private int pitCount(int x) {
            int count = 0;
            while (x > 0) {
                count += x % 2;
                x >>= 1;
            }
            return count;
        }
        
    }
}

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