当前位置:网站首页>“蔚来杯“2022牛客暑期多校训练营4 N.Particle Arts 规律 方差
“蔚来杯“2022牛客暑期多校训练营4 N.Particle Arts 规律 方差
2022-07-30 22:47:00 【HeartFireY】
N.Particle Arts
题目大意
给定序列 a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1,a2,…,an,每当两个元素 a a a和 b b b相撞后会湮灭并产生两个新元素 a & b a \& b a&b和 a ∣ b a | b a∣b。若干次碰撞后,方差会收敛。求收敛后的方差。
首先可以发现,任意两个元素相撞变化后,不会引起总和的变化,因此均值是不变的。
那么考虑求经过无限此碰撞后生成的新序列,容易发现因为或操作的性质,二进制下为 1 1 1的位不会消失,那么无限次或操作会将为 1 1 1的位向同一数字靠拢。于是直接按位统计后生成新序列计算即可。
如果使用公式 E ( x 2 ) − E 2 ( x ) E(x^2) - E^2(x) E(x2)−E2(x),需要继续推式子;但可以直接怼上方差公式,但是又会爆long long
,那么可以在运算过程中全部使用__int128
计算,最后转long long
输出。
Code
#include <bits/stdc++.h>
#pragma gcc optimize("O2")
#pragma g++ optimize("O2")
#define int __int128
#define endl '\n'
using namespace std;
const int N = 2e5 + 10, MOD = 1e9 + 7;
long long a[N], b[N], cnt[20];
inline void solve(){
long long n = 0, sum = 0; cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i], sum += a[i];
int cnt0 = 0, cnt1 = 0;
for(int i = 1; i <= n; i++){
for(int j = 0; j < 15; j++){
if((a[i] >> j) & 1) cnt[j]++;
}
}
for(int i = 0; i < 15; i++){
for(int j = 1; j <= cnt[i]; j++) b[j] |= (1 << i);
}
int f1 = 0;
for(int i = 1; i <= n; i++){
f1 += (n * b[i] - sum) * (n * b[i] - sum);
}
int f2 = n * n * n;
int gcdd = __gcd(f1, f2);
//cout << f1 << '@' << f2 << endl;
long long ans1 = f1 / gcdd, ans2 = f2 / gcdd;
//cout << (f1 / gcdd) << '/' << (f2 / gcdd) << endl;
cout << ans1 << '/' << ans2 << endl;
}
signed main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout << fixed << setprecision(12);
int t = 1; //cin >> t;
while(t--) solve();
return 0;
}
边栏推荐
- 通过社交媒体建立个人IP的 5 种行之有效的策略
- 【科研】文献下载神器方式汇总
- MySQL 5.7详细下载安装配置教程
- Ningbo Zhongning Pawn will transfer 29.5% of the equity for 2.8338 million yuan, and the owner's equity in 2021 will be 9.6875 million yuan
- Rust编译报错:error: linker `cc` not found
- MySQL连接时出现2003错误
- EasyExcel综合课程实战
- 【Summary】机器人方法汇总
- MySQL 8.0.29 set and modify the default password
- MySQL cursors
猜你喜欢
go版本升级
ThinkPHP high imitation blue play cloud network disk system source code / docking easy payment system program
Alibaba Cloud video on demand + project combat
[MySQL] DQL related operations
win10重建索引
【Untitled】
PhpMetrics 使用
#yyds干货盘点# 面试必刷TOP101:判断链表中是否有环
通过社交媒体建立个人IP的 5 种行之有效的策略
使用LVS和Keepalived搭建高可用负载均衡服务器集群
随机推荐
Solve npm warn config global `--global`, `--local` are deprecated. use `--location=global` instead
Go语学习笔记 - gorm使用 - 事务操作 Web框架Gin(十一)
MySQL 8.0.29 解压版安装教程(亲测有效)
Apache Doris系列之:深入认识实时分析型数据库Apache Doris
MySql 5.7.38 download and installation tutorial, and realize the operation of MySql in Navicat
【高等数学】矩阵与向量组的秩和等价
通过对抗性知识蒸馏压缩深度图神经网络
MySQL 8.0.29 decompressed version installation tutorial (valid for personal testing)
Golang go-redis cluster模式下不断创建新连接,效率下降问题解决
IDEA2021.2安装与配置(持续更新)
DFS题单以及模板汇总
Mysql进阶优化篇01——四万字详解数据库性能分析工具(深入、全面、详细,收藏备用)
WSL安装图形界面并通过xrdp/X-Launch访问
PhpMetrics 使用
Learning about XML (1)
mysql去除重复数据
MySQL压缩包方式安装,傻瓜式教学
1064 Complete Binary Search Tree
482-静态库、动态库的制作、使用及区别
openim支持十万超级大群