QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#472080#7932. AND-OR closureucup-team052#RE 1ms6052kbC++142.2kb2024-07-11 14:23:142024-07-11 14:23:15

Judging History

你现在查看的是最新测评结果

  • [2024-07-11 14:23:15]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:6052kb
  • [2024-07-11 14:23:14]
  • 提交

answer

#include<bits/stdc++.h>
#ifdef xay5421
#define D(...) fprintf(stderr,__VA_ARGS__)
#define DD(...) D(#__VA_ARGS__ "="),debug_helper::debug(__VA_ARGS__),D("\n")
#include"/home/xay5421/debug.hpp"
#else
#define D(...) ((void)0)
#define DD(...) ((void)0)
#endif
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define each(x,v) for(auto&x:v)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
template<class T>void rd(T&x){int f=0,c;while(!isdigit(c=getchar()))f^=!(c^45);x=(c&15);while(isdigit(c=getchar()))x=x*10+(c&15);if(f)x=-x;}
template<class T>void pt(T x,int c=-1){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);if(c!=-1)putchar(c);}
using namespace std;
using LL=long long;
using ULL=unsigned long long;
const int N=200005;
int n;
LL a[N],b[N],w[40];
int main(){
#ifdef xay5421
	freopen("a.in","r",stdin);
#endif
	rd(n);
	LL zero=0;
	rep(i,1,n)rd(a[i]),zero&=a[i];
	rep(i,1,n)a[i]^=zero;
	vector<pair<LL,int> >v;
	rep(bit,0,39){
		w[bit]=(1LL<<40)-1;
		int tt=0;
		rep(i,1,n)if(a[i]>>bit&1){
			w[bit]&=a[i];
			++tt;
		}
		if(tt){
			v.eb(w[bit],bit);
		}
	}
	sort(v.begin(),v.end());
	vector<int>V;
	for(int i=0,j;i<SZ(v);i=j){
		j=i+1;
		while(j<SZ(v)&&v[i].first==v[j].first)++j;
		V.pb(v[i].second);
	}
	vector<vector<int> >e(SZ(V));
	vector<int>deg(SZ(V));
	rep(i,0,SZ(V)-1)rep(j,0,SZ(V)-1)if(i!=j&&(w[V[j]]>>V[i]&1)){
		e[i].pb(j);
		++deg[j];
	}
	queue<int>que;
	rep(i,0,SZ(V)-1)if(!deg[i])que.push(i);
	vector<int>ord;
	while(!que.empty()){
		int u=que.front();
		que.pop();
		ord.pb(u);
		for(auto&x:e[u])if(!--deg[x])que.push(x);
	}
	
	rep(i,0,SZ(ord)-1){
		rep(j,0,SZ(ord)-1)if(w[ord[i]]>>ord[j]&1){
			assert(j<=i);
			b[ord[i]]|=1LL<<j;
		}
	}
	int C=SZ(ord)/2;
	vector<int>f(1<<C);
	rep(i,0,(1<<C)-1){
		LL st=0;
		rep(j,0,C-1){
			if(i>>j&1){
				st|=b[ord[j]];
			}
		}
		f[st]=1;
	}
	for(int i=1;i<(1<<C);i<<=1)for(int j=0;j<(1<<C);j+=i<<1)for(int k=0;k<i;++k)f[j+k]+=f[i+j+k];
	LL ans=0;
	rep(i,0,(1<<(SZ(ord)-C))-1){
		LL st=0;
		rep(j,0,SZ(ord)-C-1){
			if(i>>j&1){
				st|=b[ord[j+C]];
			}
		}
		if((st>>C)==i){
			ans+=f[st&((1<<C)-1)];
		}
	}
	printf("%lld\n",ans);
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3812kb

input:

4
0 1 3 5

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 1ms
memory: 6052kb

input:

5
0 1 2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #3:

score: -100
Runtime Error

input:

49
1097363587067 1096810445814 275012137504 1096739142630 1096809921522 1087071335264 829364908576 949625500192 1087142638448 1096200190829 1097292808175 1095750860656 1087144145776 1097346808827 1095734082416 1096755396578 829230678048 1095663303524 1087072842592 1096216444777 949623992864 10962714...

output:


result: