結果

問題 No.206 数の積集合を求めるクエリ
ユーザー akakimidoriakakimidori
提出日時 2019-04-27 02:11:52
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,200 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 30,440 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-17 06:51:19
合計ジャッジ時間 5,326 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 WA -
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 0 ms
4,376 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
権限があれば一括ダウンロードができます

ソースコード

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, i32 *cnt) {
  i32 res = 0;
  for (i32 i = 0; i < 8; ++i, n >>= 8) {
    res += cnt[n & 0xFFFF];
  }
  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 (256, sizeof (i32));
  for (i32 i = 0; i < 256; ++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