結果

問題 No.206 数の積集合を求めるクエリ
ユーザー akakimidoriakakimidori
提出日時 2019-04-27 02:15:26
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 644 ms / 7,000 ms
コード長 1,202 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 30,976 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-04 13:55:48
合計ジャッジ時間 5,005 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 22 ms
5,376 KB
testcase_18 AC 12 ms
5,376 KB
testcase_19 AC 20 ms
5,376 KB
testcase_20 AC 12 ms
5,376 KB
testcase_21 AC 14 ms
5,376 KB
testcase_22 AC 14 ms
5,376 KB
testcase_23 AC 21 ms
5,376 KB
testcase_24 AC 514 ms
5,376 KB
testcase_25 AC 510 ms
5,376 KB
testcase_26 AC 644 ms
5,376 KB
testcase_27 AC 295 ms
5,376 KB
testcase_28 AC 472 ms
5,376 KB
testcase_29 AC 485 ms
5,376 KB
testcase_30 AC 372 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef uint64_t u64;

i32 popcnt (u64 n, const i32 *cnt) {
  i32 res = 0;
  while (n > 0) {
    res += cnt[n & 0xFF];
    n >>= 8;
  }
  return res;
}

void run (void) {
  i32 l, m, n;
  scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &l, &m, &n);
  const i32 f = 8 * sizeof (u64);
  i32 len = (n + 1) / f + 1;
  u64 *a = (u64 *) calloc (len, sizeof (u64));
  u64 *b = (u64 *) calloc (len, sizeof (u64));
  while (l--) {
    i32 v;
    scanf ("%" SCNi32, &v);
    a[v / f] |= (u64)1 << (v % f);
  }
  while (m--) {
    i32 v;
    scanf ("%" SCNi32, &v);
    b[v / f] |= (u64)1 << (v % f);
  }
  i32 *cnt = (i32 *) calloc (1 << 8, sizeof (i32));
  for (i32 i = 0; i < (1 << 8); ++i) {
    i32 t = i;
    while (t > 0) {
      cnt[i]++;
      t -= t & -t;
    }
  }
  i32 q;
  scanf ("%" SCNi32, &q);
  while (q--) {
    i32 ans = 0;
    for (i32 j = 0; j < len; ++j) {
      ans += popcnt (a[j] & b[j], cnt);
    }
    printf ("%" PRIi32 "\n", ans);
    for (i32 j = len - 1; j > 0; --j) {
      b[j] = (b[j] << 1) | (b[j - 1] >> (f - 1));
    }
    b[0] <<= 1;
  }
}

int main (void) {
  run();
  return 0;
}
0