#include #include #include #include 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; }