【题解】 CF734F 【Anton and School】
2024-10-20 21:03:57
题解 CF734F 【Anton and School】
这种将位运算和普通运算结合起来的题目要拆位来考虑,可以得到\(log_{2}(\)值域\()\)的算法,甚至将值域看成常数。
根据
\(a|b+a \& b=a+b\)
得到
\(b_i+c_i=\Sigma a_i+na_i\)
于是
\(a_i=\frac{b_i+c_i- \Sigma a_i}{n}\)
根据这个式子,直接得到\(a_i\),注意在除的时候判断整除以免非法情况出现。
此时,我们要判断\(b_i\)和\(c_i\)是否真的合法,考虑到位运算的性质,我们开个\(cnt[x]\),记录所有\(a_i\)在二进制第\(x\)位出现的次数,此时,我们只需要检验——
\(b_i=2^k \times cnt[k]\)
\(c_i=\Sigma a_i+2^k \times (n-cnt[k])\)
这里的\(k\)满足
\(a_i\&(1<<(k-1))\)
总复杂度\(O(nlog(\)值域\())\),相当于\(O(n)\),但理论上会爆\(unsigned\) \(long\) \(long\) 但是它没有爆。
极其丑陋的代码
#include<bits/stdc++.h>
#define RP(t,a,b) for(register int (t)=(a),edd_=(b);t<=edd_;++t)
#define qit return puts("-1"),0
using namespace std;typedef unsigned long long ll;
template<class ccf> inline ccf qr(ccf k){
char c=getchar();
ccf x=0;
int q=1;
while(c<48||c>57)q=c==45?-1:q,c=getchar();
while(c>=48&&c<=57)x=x*10+c-48,c=getchar();
return q==-1?-x:x;
}
const int maxn=200005;
ll a[maxn];
ll b[maxn];
ll c[maxn];
ll cnt[65];
ll n;ll sum;
int main(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif
n=qr(1);
RP(t,1,n)
b[t]=qr(1ll);
RP(t,1,n)
c[t]=qr(1ll);
RP(t,1,n)
sum+=b[t]+c[t];
if(sum%(n<<1))
qit;
sum/=(n<<1);
RP(t,1,n){
a[t]=b[t]+c[t]-sum;
if(a[t]%n)
qit;//宏
else
a[t]/=n;
RP(i,1,63)
if((a[t]&(1ll<<(i-1))))
cnt[i]++;
}
ll temp=0;
RP(t,1,n){
temp=0;
RP(i,1,63)
if(a[t]&(1ll<<(i-1)))
temp+=cnt[i]*(1ll<<(i-1));
if(temp!=b[t])
qit;//宏
temp=sum;
RP(i,1,63)
if(a[t]&(1ll<<(i-1)))
temp+=(n-cnt[i])*(1ll<<(i-1));
if(temp!=c[t])
qit;//宏
}
RP(t,1,n)
cout<<a[t]<<' ';
puts("");
return 0;
}
最新文章
- struts 文件下载
- 学习git config配置文件
- css技术
- Nodejs学习(四)- express目录的分析
- JavaScript内存优化
- Project简介
- js基础知识温习:js中的对象
- Runtime类
- winform中拖动功能实现技巧
- POJ 2538 WERTYU水的问题
- IOS学习之路六(UITableView滑动删除指定行)
- 仿网易新闻app下拉标签选择菜单
- git的merge功能
- Codeforces 1083C Max Mex [线段树]
- 口碑订单,ERP本地加/退菜无法回流至手机端的解决办法-订单金额不统一erp本地加菜H5没有
- Python画图代码
- C# Hadoop学习笔记(二)—架构原理
- 二、K3 WISE 开发插件《 工业单据老单客户端插件事件、属性、方法》
- linux大小写转换
- Focalprice李培亮:梦想让人在我店里排队
热门文章
- 使用OPENROWSET爆破SQL Server密码
- Light oj 1233 - Coin Change (III) (背包优化)
- Java中获取当前时间并格式化
- 通达OA 小飞鱼工作流在线培训教程(七)工作流应用的意义及基础设置(图文)
- 2016.11.10 Could not get JDBC Connection; nested exception is java.sql.SQLException: No suitable driver
- mysql莫名的主键重复
- UNP学习笔记(第四章 基本TCP套接字编程)
- bottle的几个小坑
- 3、C++新的关键字
- Deploying Docker images via SSH