結果

問題 No.206 数の積集合を求めるクエリ
コンテスト
ユーザー fura
提出日時 2020-07-28 00:08:12
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 804 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,869 ms
コンパイル使用メモリ 210,060 KB
実行使用メモリ 7,976 KB
最終ジャッジ日時 2026-06-11 18:28:23
合計ジャッジ時間 4,725 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

inline int popcount(unsigned long long x){
	x-=(x>>1)&0x5555555555555555LL;
	x=(x&0x3333333333333333LL)+((x>>2)&0x3333333333333333LL);
	x=(x+(x>>4))&0x0f0f0f0f0f0f0f0fLL;
	x=(x*0x0101010101010101LL)>>56;
	return x;
}

int main(){
	int m,n; scanf("%d%d%*d",&m,&n);

	unsigned long long A[1570]={},B[1570]={};
	rep(i,m){ int a; scanf("%d",&a); A[a/64]|=1LL<<a%64; }
	rep(i,n){ int b; scanf("%d",&b); B[b/64]|=1LL<<b%64; }

	int q; scanf("%d",&q);
	rep(i,q){
		int d1=i/64,d2=i%64;
		int ans=0;
		rep(x,1570-d1){
			if(x==0 || d2==0){
				ans+=popcount(A[x]&(B[x+d1]<<d2));
			}
			else{
				ans+=popcount(A[x]&((B[x+d1]<<d2)|(B[x+d1-1]>>64-d2)));
			}
		}
		printf("%d\n",ans);
	}

	return 0;
}
0