結果

問題 No.206 数の積集合を求めるクエリ
ユーザー airisairis
提出日時 2015-05-09 15:43:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 811 ms / 7,000 ms
コード長 1,666 bytes
コンパイル時間 599 ms
コンパイル使用メモリ 73,708 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-19 09:29:20
合計ジャッジ時間 8,039 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 3 ms
4,384 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 27 ms
4,380 KB
testcase_13 AC 23 ms
4,380 KB
testcase_14 AC 27 ms
4,380 KB
testcase_15 AC 26 ms
4,380 KB
testcase_16 AC 26 ms
4,376 KB
testcase_17 AC 53 ms
4,376 KB
testcase_18 AC 28 ms
4,380 KB
testcase_19 AC 48 ms
4,376 KB
testcase_20 AC 28 ms
4,380 KB
testcase_21 AC 35 ms
4,376 KB
testcase_22 AC 34 ms
4,380 KB
testcase_23 AC 49 ms
4,380 KB
testcase_24 AC 811 ms
4,384 KB
testcase_25 AC 806 ms
4,384 KB
testcase_26 AC 783 ms
4,380 KB
testcase_27 AC 570 ms
4,380 KB
testcase_28 AC 790 ms
4,380 KB
testcase_29 AC 794 ms
4,376 KB
testcase_30 AC 776 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <numeric>
#include <bitset>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define foreach(itr, x) for (typeof((x).begin()) itr = (x).begin(); itr != (x).end(); itr++)

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;

typedef unsigned long long ull;

int L, M, N, Q;
ull A[1605];
ull B[1605];
ull C[1605];
ull x;
int SIZE = sizeof(ull)*8;
int table16[(1<<16) + 5];

void solve() {
#if 0
	rep(i, 3) {
		rep(j, 64) {
			printf("%d:%d\n", i*64+j,(A[i]&(1LL<<j)) > 0);
		}
	}
	puts("");
#endif
	rep(i, Q) {
		int ans = 0;
		for (int j = 1600; j >= 0; j--) {
			if (i > 0) {
				B[j] <<= 1ULL;
				if (j - 1 >= 0)  {
					B[j] |= ((B[j-1] & (1ULL<<(SIZE-1)))>0); //1つ前の最上位bit立ってたら、もってくる
				}
			}
			C[j] = A[j] & B[j];
			ans += table16[(C[j] & 0x000000000000ffffULL)];
			ans += table16[(C[j] & 0x00000000ffff0000ULL)>>16];
			ans += table16[(C[j] & 0x0000ffff00000000ULL)>>32];
			ans += table16[(C[j] & 0xffff000000000000ULL)>>48];
			//cout << ans << endl;
		}
		cout << ans << endl;
	}
}

int main() {
	cin >> L >> M >> N;
	rep(i, L) {
		cin>> x; x--;
		A[x/SIZE] |= (1ULL << (x % SIZE));
	}
	rep(i, M) {
		cin>> x; x--;
		B[x/SIZE] |= (1ULL << (x % SIZE));
	}
	cin >> Q;
	rep(i, 1 << 16) {
		table16[i] = 0;
		rep(j, 16) {
			table16[i] += ((i & (1 << j)) > 0);
		}
	}
	solve();
	return 0;
}


0