社区讨论

求卡常

P13818「LDOI R3」泡泡抗特参与者 4已保存回复 4

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
4 条
当前快照
1 份
快照标识符
@mjxpzsfg
此快照首次捕获于
2026/01/03 11:05
2 个月前
此快照最后确认于
2026/01/06 16:55
上个月
查看原帖
CPP
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
const int N=3e5+10; 

void redi (__int128& ret) {
    ret=0;int f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f;ch=getchar();}
    while(ch>='0'&&ch<='9')ret=ret*10+ch-'0',ch=getchar();
    ret*=f;
} 

int t,n;
__int128 a[N];
unordered_map<int,long long> mp1[200],mp;
 
__int128 lowbit(__int128 x){
	return x&(-x);
}

int popcount(__int128 x){
	int ans=0;
	while(x){
		x-=lowbit(x);
		ans++;
	}
	return ans;
}

int w(__int128 x){
	int res=0;
	while(x){
		res++;
		x/=2;
	}
	return res;
}

int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		long long ans=0;
		for(int i=0;i<=120;i++){
			for(int j=0;j<=120;j++){
				mp1[i][j]=0;
			}
			mp[i]=0;
		}
		for(int i=1;i<=n;i++){
			redi(a[i]);
			int k=popcount(a[i]);
			if(k==1) mp[w(lowbit(a[i]))]++;
			if(k==2) mp1[w(lowbit(a[i]-lowbit(a[i])))][w(lowbit(a[i]))]++;
		}
		for(int i=0;i<=120;i++){
			for(int j=i+1;j<=120;j++){
				ans=(ans+mp[i]*mp[j]*mp1[j][i])%mod;
				for(int k=j+1;k<=120;k++){
					ans=(ans+mp1[j][i]*mp1[k][i]*mp1[k][j])%mod;
				}
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}

回复

4 条回复,欢迎继续交流。

正在加载回复...