結果

問題 No.206 数の積集合を求めるクエリ
ユーザー tentententen
提出日時 2023-01-27 09:20:16
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 3,352 bytes
コンパイル時間 3,055 ms
コンパイル使用メモリ 95,624 KB
実行使用メモリ 48,816 KB
最終ジャッジ日時 2024-06-27 21:24:10
合計ジャッジ時間 49,492 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
36,788 KB
testcase_01 AC 51 ms
36,700 KB
testcase_02 AC 54 ms
36,904 KB
testcase_03 AC 52 ms
36,928 KB
testcase_04 AC 52 ms
36,660 KB
testcase_05 AC 53 ms
36,796 KB
testcase_06 AC 78 ms
38,540 KB
testcase_07 AC 85 ms
38,200 KB
testcase_08 AC 92 ms
38,536 KB
testcase_09 AC 81 ms
38,856 KB
testcase_10 AC 52 ms
37,160 KB
testcase_11 AC 52 ms
37,244 KB
testcase_12 AC 138 ms
40,720 KB
testcase_13 AC 109 ms
40,068 KB
testcase_14 AC 108 ms
40,408 KB
testcase_15 AC 103 ms
40,504 KB
testcase_16 AC 103 ms
40,280 KB
testcase_17 AC 262 ms
46,172 KB
testcase_18 AC 230 ms
44,620 KB
testcase_19 AC 262 ms
46,204 KB
testcase_20 AC 207 ms
44,740 KB
testcase_21 AC 236 ms
45,572 KB
testcase_22 AC 215 ms
44,904 KB
testcase_23 AC 285 ms
45,892 KB
testcase_24 AC 6,862 ms
48,816 KB
testcase_25 AC 6,947 ms
48,752 KB
testcase_26 TLE -
testcase_27 AC 3,659 ms
48,076 KB
testcase_28 AC 6,108 ms
47,348 KB
testcase_29 AC 6,504 ms
47,632 KB
testcase_30 AC 3,939 ms
47,764 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++) {
            BitArray x = a.and(b);
            sb.append(x.getCount()).append("\n");
            a.shift();
        }
        System.out.print(sb);
    }
    
    static class BitArray {
        long[] arr;
        int size;
        
        public BitArray(int x) {
            size = (x + 60 - 1) / 60;
            arr = new long[size];
        }
        
        public BitArray(int size, long[] arr) {
            this.size = size;
            this.arr = arr;
        }
        
        public void setBit(int x) {
            arr[x / 60] |= (1L << (x % 60));
        }
        
        public void shift() {
            long add = 0;
            for (int i = size - 1; i >= 0; i--) {
                arr[i] += (add << 60);
                add = arr[i] % 2;
                arr[i] >>= 1;
            }
        }
        
        public BitArray and(BitArray x) {
            long[] ans = new long[size];
            for (int i = 0; i < size; i++) {
                ans[i] = (arr[i] & x.arr[i]);
            }
            return new BitArray(size, ans);
        }
        
        public long getCount() {
            long count = 0;
            for (long x : arr) {
                count += pitCount(x);
            }
            return count;
        }
        
        private long pitCount(long x) {
            long 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