• C. Make Good


    C. Make Good

    C. Make Good

    time limit per test

    2 seconds

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    Let's call an array a1,a2,…,ama1,a2,…,am of nonnegative integer numbers good if a1+a2+⋯+am=2⋅(a1⊕a2⊕⋯⊕am)a1+a2+⋯+am=2⋅(a1⊕a2⊕⋯⊕am), where ⊕⊕ denotes the bitwise XOR operation.

    For example, array [1,2,3,6][1,2,3,6] is good, as 1+2+3+6=12=2⋅6=2⋅(1⊕2⊕3⊕6)1+2+3+6=12=2⋅6=2⋅(1⊕2⊕3⊕6). At the same time, array [1,2,1,3][1,2,1,3] isn't good, as 1+2+1+3=7≠2⋅1=2⋅(1⊕2⊕1⊕3)1+2+1+3=7≠2⋅1=2⋅(1⊕2⊕1⊕3).

    You are given an array of length nn: a1,a2,…,ana1,a2,…,an. Append at most 33 elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.

    Input

    Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤100001≤t≤10000). The description of the test cases follows.

    The first line of each test case contains a single integer nn (1≤n≤105)(1≤n≤105) — the size of the array.

    The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤ai≤109) — the elements of the array.

    It is guaranteed that the sum of nn over all test cases does not exceed 105105.

    Output

    For each test case, output two lines.

    In the first line, output a single integer ss (0≤s≤30≤s≤3) — the number of elements you want to append.

    In the second line, output ss integers b1,…,bsb1,…,bs (0≤bi≤10180≤bi≤1018) — the elements you want to append to the array.

    If there are different solutions, you are allowed to output any of them.

    Example

    input

    Copy

    3
    4
    1 2 3 6
    1
    8
    2
    1 1
    

    output

    Copy

    0
    
    2
    4 4
    3
    2 6 2
    

    Note

    In the first test case of the example, the sum of all numbers is 1212, and their ⊕⊕ is 66, so the condition is already satisfied.

    In the second test case of the example, after adding 4,44,4, the array becomes [8,4,4][8,4,4]. The sum of numbers in it is 1616, ⊕⊕ of numbers in it is

    ==================================================================================

    还是说根据3这个限制条件来寻求通解

    设原数组前缀和sum,异或和xor

    第一步 加一个元素xor 

    sum=sum+xor  xor=0

    第二步,再加一个原数组的sum+xor

    sum=2*(sum+xor)  xor =sum+xor

    大功告成

    1. # include
    2. # include
    3. # include
    4. # include
    5. # include
    6. using namespace std;
    7. typedef long long int ll;
    8. int main ()
    9. {
    10. int t;
    11. cin>>t;
    12. while(t--)
    13. {
    14. int n;
    15. cin>>n;
    16. ll now=0,sum=0,x;
    17. for(int i=1;i<=n;i++)
    18. {
    19. cin>>x;
    20. now^=x;
    21. sum+=x;
    22. }
    23. cout<<2<
    24. cout<" "<
    25. }
    26. return 0;
    27. }

  • 相关阅读:
    18.(开发工具篇Gitlab)Git如何回退到指定版本
    Could not resolve placeholder ‘jdbc.driver‘ in string value “${jdbc.driver}“
    《数字图像处理(MATLAB版)》相关算法代码及其分析(1)
    java-数据迁移-定制拓展
    【Java】微服务——Feign远程调用
    [ros2实操]1-ros2的安装(ubuntu1804)与运行
    Java集合篇之逐渐被遗忘的Stack,手写一个栈你会吗?
    挑战10个最难回答的Java面试题(附答案)
    vue+element如何实现可编辑表格?
    【翻译】Seastar 教程(四)
  • 原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126305390