题目链接:https://codeforces.com/contest/1270/problem/C
题意:给定n个数(1<=n<=1e5)ai(1<=ai<=1e9),现在在原数组种添加最多3个数(范围为1到1e18),使得新数组满足
题解:
定义原数组的累加和为
,异或和为
,那么当
时,我们可以在两边添加2个数
即可;
(偷看了官方题解)为了保证最后得到的新数组的
,我们可以在数组加上数
,其正确性易证。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=200010;
int n;
int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
ll s=0,x=0,a;
for(int i=1;i<=n;i++){
scanf("%I64d",&a);
s+=a;
x^=a;
}
a=(1LL<<50)+(s%2);
s+=a;x^=a;
ll ans=(x*2-s)/2;
printf("3\n%I64d %I64d %I64d\n",a,ans,ans);
}
return 0;
}