位运算。

两个数的和:$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. j2ee 项目部署指引

    j2ee相关的项目一般是web工程或java application,部署到linux服务器上,本文结合自己的经验.教训,总结下部署的过程. 一.准备阶段 部署前要做的事情: 1.明确自己的产品都包含 ...

  2. 2015/9/4 Python基础(8):映射和集合类型

    Python里唯一的映射类型是字典.映射类型对象里,hash值(key)和指向的对象(值)是一对多的关系.字典对象是可变的,这一点上很像列表,它也可以存储任意个数任意类型的Python对象,其中包括容 ...

  3. sql cmd命令执行sqlserver的sql文件

    有的时候,我们通过Log Explorer工具根据日志生成的回滚脚本,或者其他情况我们得到的脚本文件,通过sqlserver打开脚本文件的方式不爽,我们可以这样: 方式一: osql -S . -U ...

  4. Everything Has Changed(HDU6354+圆交+求周长)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6354 题目: 题意:用一堆圆来切割一个圆心为原点,半径为R的圆A,问切割完毕后圆A外围剩余部分的周长( ...

  5. zabbix的命令执行

    1.对于低版本的可用下列exp直接打到用户 http://119.29.48.232/zabbix/httpmon.php?applications=2 and (select 1 from (sel ...

  6. poj 2762 tarjan缩点+拓扑序

    2013-09-08 10:00 var m, n :longint; t :longint; f, last :..] of longint; pre, other :..] of longint; ...

  7. Webview 中FaultyInfo代码说明

    class FaultyInfoHandler(tornado.web.RequestHandler): def get(self): import xmlrpc.client s = xmlrpc. ...

  8. 第一章: 文件句柄转化为 typeglob/glob 与文件句柄检测

    #为了使在子例程中传递文件句柄不出问题 #我们要把文件句柄转为glob或typeglob #转为glob $fd = *MY_FILE; #转为typeblog $fd = \*MY_FILE; #两 ...

  9. gcc中的内嵌汇编语言(Intel i386平台)

    [转]http://bbs.chinaunix.net/thread-2149855-1-1.html 一.声明  虽然Linux的核心代码大部分是用C语言编写的,但是不可避免的其中还是有一部分是用汇 ...

  10. python基础===字符串的制表,换行基础操作

    \n\t 制表符和换行符 >>> print("Languages:\n\tPython\n\tC\n\tJavaScript") Languages: Pyth ...