CF1713F.Lost Array

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

My orzlers, we can optimize this problem from O(S3)O(S^3) to O(T59)O\left(T^\frac{5}{9}\right)!

— Spyofgame, founder of Orzlim religion

A long time ago, Spyofgame invented the famous array aa (11-indexed) of length nn that contains information about the world and life. After that, he decided to convert it into the matrix bb (00-indexed) of size (n+1)×(n+1)(n + 1) \times (n + 1) which contains information about the world, life and beyond.

Spyofgame converted aa into bb with the following rules.

  • bi,0=0b_{i,0} = 0 if 0≤i≤n0 \leq i \leq n;
  • b0,i=aib_{0,i} = a_{i} if 1≤i≤n1 \leq i \leq n;
  • bi,j=bi,j−1⊕bi−1,jb_{i,j} = b_{i,j-1} \oplus b_{i-1,j} if 1≤i,j≤n1 \leq i, j \leq n.

Here ⊕\oplus denotes the bitwise XOR operation.

Today, archaeologists have discovered the famous matrix bb. However, many elements of the matrix has been lost. They only know the values of bi,nb_{i,n} for 1≤i≤n1 \leq i \leq n (note that these are some elements of the last column, not the last row).

The archaeologists want to know what a possible array of aa is. Can you help them reconstruct any array that could be aa?

我的orz信徒们,我们可以将该问题的复杂度从 O(S3)O(S^3) 优化至 O(T59)O\left(T^\frac{5}{9}\right)!

— Spyofgame,Orzlim 宗教创始人

很久以前,Spyofgame 发明了一个著名的长度为 nn 的数组 aa(下标从 11 开始),其中蕴含着关于世界与生命的全部信息。随后,他决定将其转换为一个大小为 (n+1)×(n+1)(n + 1) \times (n + 1) 的矩阵 bb(下标从 00 开始),其中蕴含着关于世界、生命乃至更深远领域的信息。

Spyofgame 按照如下规则将 aa 转换为 bb:

  • 若 0≤i≤n0 \leq i \leq n,则 bi,0=0b_{i,0} = 0;
  • 若 1≤i≤n1 \leq i \leq n,则 b0,i=aib_{0,i} = a_{i};
  • 若 1≤i,j≤n1 \leq i, j \leq n,则 bi,j=bi,j−1⊕bi−1,jb_{i,j} = b_{i,j-1} \oplus b_{i-1,j}。

此处 ⊕\oplus 表示 按位异或运算。

如今,考古学家们发现了这个著名的矩阵 bb。然而,矩阵中许多元素已经遗失。他们仅知道 bi,nb_{i,n} 的值(其中 1≤i≤n1 \leq i \leq n)(注意:这些是最后一列中的某些元素,而非最后一行)。

考古学家们希望知道一个可能的数组 aa 是什么。你能帮他们重构出一个可能的 aa 吗?

输入格式

The first line contains a single integer nn (1≤n≤5⋅1051 \leq n \leq 5 \cdot 10^5).

The second line contains nn integers b1,n,b2,n,…,bn,nb_{1,n}, b_{2,n}, \ldots, b_{n,n} (0≤bi,n<2300 \leq b_{i,n} \lt 2^{30}).

第一行包含一个整数 nn(1≤n≤5⋅1051 \leq n \leq 5 \cdot 10^5)。

第二行包含 nn 个整数 b1,n,b2,n,…,bn,nb_{1,n}, b_{2,n}, \ldots, b_{n,n}(0≤bi,n<2300 \leq b_{i,n} \lt 2^{30})。

输出格式

If some array aa is consistent with the information, print a line containing nn integers a1,a2,…,ana_1, a_2, \ldots, a_n. If there are multiple solutions, output any.

If such an array does not exist, output −1-1 instead.

如果存在某个数组 aa 满足给定信息,请输出一行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n 的结果。若存在多个解,输出任意一个即可。

若不存在满足条件的数组,则输出 −1-1。

输入输出样例

  • 输入#1

    3
    0 2 1

    输出#1

    1 2 3
  • 输入#2

    1
    199633

    输出#2

    199633
  • 输入#3

    10
    346484077 532933626 858787727 369947090 299437981 416813461 865836801 141384800 157794568 691345607

    输出#3

    725081944 922153789 481174947 427448285 516570428 509717938 855104873 280317429 281091129 1050390365

说明/提示

If we let a=[1,2,3]a = [1,2,3], then bb will be:

0\bf{0}

1\bf{1}

2\bf{2}

3\bf{3}

0\bf{0}

11

33

00

0\bf{0}

11

22

22

0\bf{0}

11

33

11

The values of b1,n,b2,n,…,bn,nb_{1,n}, b_{2,n}, \ldots, b_{n,n} generated are [0,2,1][0,2,1] which is consistent with what the archaeologists have discovered.

如果我们令 a=[1,2,3]a = [1,2,3],则 bb 将为:

0\bf{0}

1\bf{1}

2\bf{2}

3\bf{3}

0\bf{0}

11

33

00

0\bf{0}

11

22

22

0\bf{0}

11

33

11

所生成的 b1,n,b2,n,…,bn,nb_{1,n}, b_{2,n}, \ldots, b_{n,n} 的值为 [0,2,1][0,2,1],这与考古学家的发现一致。

输入解题思路,AI测评打分。不知道怎么写?

首页