結果

問題 No.1296 OR or NOR
ユーザー kotatsugamekotatsugame
提出日時 2020-11-20 23:20:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,714 bytes
コンパイル時間 905 ms
コンパイル使用メモリ 80,740 KB
実行使用メモリ 82,296 KB
最終ジャッジ日時 2023-09-30 20:05:59
合計ジャッジ時間 27,304 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,600 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 668 ms
82,008 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 666 ms
82,044 KB
testcase_18 AC 668 ms
82,008 KB
testcase_19 AC 663 ms
82,000 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 401 ms
5,444 KB
testcase_23 AC 413 ms
5,596 KB
testcase_24 AC 423 ms
5,488 KB
testcase_25 AC 426 ms
5,460 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 433 ms
5,508 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 494 ms
81,956 KB
testcase_34 AC 495 ms
81,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
a.cpp:8:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]

ソースコード

diff #

#line 1 "a.cpp"
#include<iostream>
using namespace std;
#line 1 "/home/kotatsugame/library/datastructure/DST.cpp"
//Disjoint Sparse Table
#include<vector>
#include<functional>
template<typename T>
struct DST{
	function<T(T,T)>calcfn;
	int n;
	vector<vector<T> >dat;
	DST(const vector<T>&v={},
		function<T(T,T)>calcfn_=[](T a,T b){return a<b?a:b;}
	):calcfn(calcfn_)
	{
		n=v.size();
		dat.push_back(v);
		for(int i=2;i<n;i<<=1)
		{
			dat.push_back(vector<T>(n));
			for(int j=i;j<n;j+=i<<1)
			{
				dat.back()[j-1]=dat[0][j-1];
				for(int k=2;k<=i;k++)
				{
					dat.back()[j-k]=calcfn(dat[0][j-k],dat.back()[j-k+1]);
				}
				dat.back()[j]=dat[0][j];
				for(int k=2;k<=i&&j+k<=n;k++)
				{
					dat.back()[j+k-1]=calcfn(dat.back()[j+k-2],dat[0][j+k-1]);
				}
			}
		}
	}
	T query(int l,int r)const//[l,r)
	{
		if(l<0)l=0;
		if(r>n)r=n;
		r--;
		if(l==r)return dat[0][l];
		int k=31-__builtin_clz(l^r);
		return calcfn(dat[k][l],dat[k][r]);
	}
};
#line 4 "a.cpp"
int N;
long a[2<<17];
int pre[2<<17][60];
int Q;
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>a[i];
	for(int j=0;j<60;j++)pre[0][j]=-1;
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<60;j++)pre[i+1][j]=pre[i][j];
		for(int j=0;j<60;j++)if(a[i]>>j&1)pre[i+1][j]=i;
	}
	DST<long>P(vector<long>(a,a+N),[](long a,long b){return a|b;});
	cin>>Q;
	for(;Q--;)
	{
		long b;cin>>b;
		long A=b,B=~b&(1L<<60)-1;
		int id=N;
		int ans=0;
		while(A&&id>0)
		{
			int nid=-1;
			for(int j=0;j<60;j++)if(B>>j&1&&pre[id][j]>nid)nid=pre[id][j];
			if(nid+1<id)A&=~P.query(nid+1,id);
			if(!A)break;
			id=nid;
			if(id>=0)
			{
				if(A&a[id])break;
				long tA=B&~a[id],tB=A;
				A=tA,B=tB;
				ans++;
			}
		}
		if(A==0)cout<<ans<<endl;
		else cout<<-1<<endl;
	}
}
0