1466E - Apollo versus Pan

本文主要探讨了一道与数学和编程相关的竞赛题目1466E-ApolloversusPan。作者通过代码实现,展示了如何处理位运算和数组统计,以计算特定条件下的组合数。在代码中,初始化、位操作和循环计算是关键步骤,用于求解不同数值之间的与和或操作的组合。
摘要由CSDN通过智能技术生成

1466E - Apollo versus Pan

有点数学,(

参考

话说cincout的同步真的差太多了,btw cf竟然也卡cincout
在这里插入图片描述

思路:
在这里插入图片描述

code

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 5e5 + 10, M = 70;
const ll mod = 1e9 + 7;

ll a[N], have[M], pow2[M];

inline void init1() {
	pow2[0] = 1;
	for(int i = 1; i <= 65; ++ i) {
		pow2[i] = pow2[i - 1] * 2 % mod;
	}
}

inline void init() {
	memset(have, 0, sizeof have);
}

int main() {
#ifdef ONLINE_JUDGE
#else
    freopen("in.txt","r",stdin);
#endif

	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 

	init1();
	
	int T;
	cin >> T;
	while(T--) {
		init();
		ll n;
		cin >> n;
		for(int i = 1; i <= n; ++ i) {
			cin >> a[i];
			for(int j = 0; j <= 60; ++ j) {
				int u = a[i] >> j & 1;
				if(u) ++ have[j];
			}
		}
		
		ll ans = 0;
		for(int i = 1; i <= n; ++ i) {
			ll ansOfAnd = 0;
			ll ansOfOr = 0;
			for(int j = 0; j <= 60; ++ j) {
				if(a[i] >> j & 1) {
					ansOfAnd = (ansOfAnd + pow2[j] * have[j]) % mod;
					ansOfOr = (ansOfOr + pow2[j] * n) % mod;
				}
				else {
					ansOfOr = (ansOfOr + pow2[j] * have[j]) % mod;
				}
			}
			ans = (ans + ansOfAnd * ansOfOr % mod) % mod;
		}
		
		cout << ans << endl;
	}
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值