結果

問題 No.206 数の積集合を求めるクエリ
ユーザー fura
提出日時 2020-07-28 00:18:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 380 ms / 7,000 ms
コード長 746 bytes
コンパイル時間 2,291 ms
コンパイル使用メモリ 191,952 KB
最終ジャッジ日時 2025-01-12 07:03:24
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:16:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |         int m,n; scanf("%d%d%*d",&m,&n);
      |                  ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:19:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |         rep(i,m){ int a; scanf("%d",&a); A[a/64]|=1ULL<<a%64; }
      |                          ~~~~~^~~~~~~~~
main.cpp:20:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |         rep(i,n){ int b; scanf("%d",&b); B[b/64]|=1ULL<<b%64; }
      |                          ~~~~~^~~~~~~~~
main.cpp:22:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |         int q; scanf("%d",&q);
      |                ~~~~~^~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

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

using namespace std;

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[1600]={},B[1600]={};
	rep(i,m){ int a; scanf("%d",&a); A[a/64]|=1ULL<<a%64; }
	rep(i,n){ int b; scanf("%d",&b); B[b/64]|=1ULL<<b%64; }

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

	return 0;
}
0