位运算。

两个数的和:$A+B=(AandB)+(AorB)$,那么$b[i]+c[i]=n*a[i]+suma$。可以解出一组解,然后再按位统计贡献验证一下。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar();
x = ;
while(!isdigit(c)) c = getchar();
while(isdigit(c))
{
x = x * + c - '';
c = getchar();
}
} LL sum,sumc,sumb;
LL t[],g[],a[],b[],c[];
int n; int main()
{
g[]=; for(int i=;i<=;i++) g[i]=g[i-]*;
cin>>n;
for(int i=;i<=n;i++)
{
cin>>b[i];
sumb=sumb+b[i];
} for(int i=;i<=n;i++)
{
cin>>c[i];
sumc=sumc+c[i];
} if((sumb+sumc)%(LL)(*n)!=)
{
printf("-1\n");
return ;
} sum=(sumb+sumc)/(LL)(*n); for(int i=;i<=n;i++)
{
if((b[i]+c[i]-sum)<)
{
printf("-1\n");
return ;
} if((b[i]+c[i]-sum)%(LL)n!=)
{
printf("-1\n");
return ;
} a[i]=(b[i]+c[i]-sum)/(LL)n;
} for(int i=;i<=n;i++)
for(int j=;j<=;j++) if(a[i]&g[j]) t[j]++; bool fail=; for(int i=;i<=n;i++)
{
long long sum=;
for(int j=;j<=;j++) if(a[i]&g[j]) sum=sum+t[j]*g[j];
if(sum!=b[i]) fail=; sum=;
for(int j=;j<=;j++)
{
if(a[i]&g[j]) sum=sum+n*g[j];
else sum=sum+t[j]*g[j];
}
if(sum!=c[i]) fail=;
} if(fail==)
{
for(int i=;i<=n;i++) cout<<a[i]<<" ";
cout<<endl;
}
else cout<<"-1"<<endl; return ;
}

CodeForces 734F Anton and School的更多相关文章

  1. Codeforces 734F Anton and School(位运算)

    [题目链接] http://codeforces.com/problemset/problem/734/F [题目大意] 给出数列b和数列c,求数列a,如果不存在则输出-1 [题解] 我们发现: bi ...

  2. 【codeforces 734F】Anton and School

    [题目链接]:http://codeforces.com/problemset/problem/734/F [题意] 给你两个数组b和c; 然后让你找出一个非负数组a满足题中所给关系; [题解] 有个 ...

  3. Codeforces 734E. Anton and Tree 搜索

    E. Anton and Tree time limit per test: 3 seconds memory limit per test :256 megabytes input:standard ...

  4. Codeforces 593B Anton and Lines

    LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output st ...

  5. [刷题]Codeforces 785D - Anton and School - 2

    Description As you probably know, Anton goes to school. One of the school subjects that Anton studie ...

  6. Codeforces 785D - Anton and School - 2 - [范德蒙德恒等式][快速幂+逆元]

    题目链接:https://codeforces.com/problemset/problem/785/D 题解: 首先很好想的,如果我们预处理出每个 "(" 的左边还有 $x$ 个 ...

  7. Codeforces 584E - Anton and Ira - [贪心]

    题目链接:https://codeforces.com/contest/584/problem/E 题意: 给两个 $1 \sim n$ 的排列 $p,s$,交换 $p_i,p_j$ 两个元素需要花费 ...

  8. Codeforces 785E. Anton and Permutation

    题目链接:http://codeforces.com/problemset/problem/785/E 其实可以CDQ分治... 我们只要用一个数据结构支持单点修改,区间查询比一个数大(小)的数字有多 ...

  9. Codeforces 734E Anton and Tree(缩点+树的直径)

    题目链接: Anton and Tree 题意:给出一棵树由0和1构成,一次操作可以将树上一块相同的数字转换为另一个(0->1 , 1->0),求最少几次操作可以把这棵数转化为只有一个数字 ...

随机推荐

  1. LightOJ 1140 计数/数位DP 入门

    题意: 给出a,b求区间a,b内写下过多少个零 题解:计数问题一般都会牵扯到数位DP,DP我写的少,这道当作入门了,DFS写法有固定的模板可套用 dp[p][count] 代表在p位 且前面出现过co ...

  2. async和await关键词用于定义原生的协程

    #python为了将语义变得更加明确,就引入了async和await关键词用于定义原生的协程 # async def downloader(url): # return "xxxx" ...

  3. 元类编程-- 实现orm,以django Model为例

    # 需求 import numbers class Field: pass class IntField(Field): # 数据描述符 def __init__(self, db_column, m ...

  4. 【BZOJ2693】jzptab [莫比乌斯反演]

    jzptab Time Limit: 10 Sec  Memory Limit: 512 MB[Submit][Status][Discuss] Description   求 Input 第一行一个 ...

  5. 【BZOJ】4530: [Bjoi2014]大融合

    [题意]给定n个点的树,从无到有加边,过程中动态询问当前图某条边两端连通点数的乘积,n<=10^5. [算法]线段树合并+并查集 (||LCT(LCT维护子树信息 LCT维护子树信息(+启发式合 ...

  6. Git 常用命令(二)

    用 git init 在目录中创建新的 Git 仓库.  $ mkdir test $ cd test/ $ git init Initialized empty Git repository in ...

  7. Maven学习笔记(一)

    我们暂且可以把Maven理解成是一个项目构建与依赖管理的工具   为什么选用maven? 约定(惯例)优先原则,默认限定了项目目录结构 提供三方依赖管理(解决了依赖维护的问题) 提供了一致的项目构建管 ...

  8. ribbon使用eureka的meta进行动态路由

    序 使用eureka的元数据信息,再配上ribbon的路由功能,就可以在api-gateway实现很多功能,比如灰度测试.生产调试等等.下面介绍一下,怎么使用jmnarloch大神提供的ribbon- ...

  9. ubuntu下定时弹窗记录工作日志

    背景 记录工作日志,是一个很好的习惯,但不容易坚持,本来打算每天记录,但经常拖延,拖着拖着,有一些事情就忘记了. 等到写周报或月报的时候,才会开始翻邮件,聊天记录,各个仓库的提交log等,回忆都干了些 ...

  10. Ubuntu 14.04 安装gstreamer0.10-ffmpeg

    sudo apt-add-repository ppa:mc3man/trusty-media sudo apt-get update sudo apt-get install -y gstreame ...