結果
| 問題 |
No.206 数の積集合を求めるクエリ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-03-27 03:38:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,774 bytes |
| コンパイル時間 | 524 ms |
| コンパイル使用メモリ | 56,980 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-02 03:47:51 |
| 合計ジャッジ時間 | 6,354 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 WA * 17 |
ソースコード
#include <iostream>
using namespace std;
const int maxN = 100000;
int memo[65536] = { 0 };
bool bA[maxN] = { false };
bool bB[maxN] = { false };
unsigned int A[maxN/32 + 1] = { 0 };
unsigned int B[maxN/32 + 1] = { 0 };
void fill_memo() {
for (int i = 0; i != (1 << 16); ++i) {
int cum = 0, j = i;
while (j) {
if (j & 1) ++cum;
j >>= 1;
}
memo[i] = cum;
}
}
void read_data(bool bT[], int L){
for (int i = 0, val = 0; i != L; ++i) {
cin >> val;
bT[val] = true;
}
}
void fill_array(bool bS[], unsigned int T[], int N);
int count_common(unsigned int A[], unsigned int B[], int N);
inline int bit_count(unsigned int m) {
return memo[m & 65535] + memo[m >> 16];
}
inline void shift_array(unsigned int B[], int N) {
for (int i = N / 32; i != 0; --i) {
B[i] <<= 1;
if (B[i - 1] & 32768) B[i] |= 1;
}
B[0] <<= 1;
}
template <typename Array>
void disp(Array ar[], int N) {
for (int i = 0; i <= N; ++i) cout << ar[i] << ' ';
cout << endl;
}
int main()
{
fill_memo();
int L, M, N, Q;
cin >> L >> M >> N;
read_data(bA, L);
read_data(bB, M);
// disp(bA, N);
// disp(bB, N);
cin >> Q;
fill_array(bA, A, N);
fill_array(bB, B, N);
// disp(A, N/32 + 1);
// disp(B, N/32 + 1);
for (int v = 0; v != Q; ++v) {
cout << count_common(A, B, N) << '\n';
shift_array(B, N);
}
return 0;
}
void fill_array(bool bS[], unsigned int T[], int N) {
unsigned int cum = 0, pow2 = 1;
for (int i = 0; i <= N; ++i) {
if (bS[i]) cum += pow2;
pow2 <<= 1;
if (i % 32 == 31) {
T[i / 32] = cum;
cum = 0;
pow2 = 1;
}
}
if (cum) T[N / 32] = cum;
}
int count_common(unsigned int A[], unsigned int B[], int N) {
int end = N / 32 + 1;
int count = 0;
for (int i = 0; i != end; ++i) {
count += bit_count(A[i] & B[i]);
}
return count;
}