CF923C.Perfect Security

普及+/提高

通过率:0%

时间限制:3.50s

内存限制:512MB

AC君温馨提醒

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

题目描述

Alice has a very important message M consisting of some non-negative integers that she wants to keep secret from Eve. Alice knows that the only theoretically secure cipher is one-time pad. Alice generates a random key K of the length equal to the message's length. Alice computes the bitwise xor of each element of the message and the key (, where denotes the bitwise XOR operation) and stores this encrypted message A. Alice is smart. Be like Alice.

For example, Alice may have wanted to store a message M = (0, 15, 9, 18). She generated a key K = (16, 7, 6, 3). The encrypted message is thus A = (16, 8, 15, 17).

Alice realised that she cannot store the key with the encrypted message. Alice sent her key K to Bob and deleted her own copy. Alice is smart. Really, be like Alice.

Bob realised that the encrypted message is only secure as long as the key is secret. Bob thus randomly permuted the key before storing it. Bob thinks that this way, even if Eve gets both the encrypted message and the key, she will not be able to read the message. Bob is not smart. Don't be like Bob.

In the above example, Bob may have, for instance, selected a permutation (3, 4, 1, 2) and stored the permuted key P = (6, 3, 16, 7).

One year has passed and Alice wants to decrypt her message. Only now Bob has realised that this is impossible. As he has permuted the key randomly, the message is lost forever. Did we mention that Bob isn't smart?

Bob wants to salvage at least some information from the message. Since he is not so smart, he asks for your help. You know the encrypted message A and the permuted key P. What is the lexicographically smallest message that could have resulted in the given encrypted text?

More precisely, for given A and P, find the lexicographically smallest message O, for which there exists a permutation π such that for every i.

Note that the sequence S is lexicographically smaller than the sequence T, if there is an index i such that S__i < T__i and for all j < i the condition S__j = T__j holds.

爱丽丝有一条非常重要的消息 MM,由若干个非负整数构成,她希望该消息对伊芙(Eve)保密。爱丽丝知道,唯一在理论上安全的密码体制是一次性密码本(one-time pad)。爱丽丝生成一个随机密钥 KK,其长度与消息长度相等。爱丽丝对消息中每个元素与密钥中对应元素执行按位异或运算(,其中 表示按位异或运算),并将所得加密消息记为 AA。爱丽丝很聪明。请向爱丽丝学习。

例如,爱丽丝原本想存储消息 M=(0, 15, 9, 18)M = (0,\,15,\,9,\,18)。她生成密钥 K=(16, 7, 6, 3)K = (16,\,7,\,6,\,3)。于是加密消息为 A=(16, 8, 15, 17)A = (16,\,8,\,15,\,17)。

爱丽丝意识到,她不能将密钥与加密消息一同存储。于是她把密钥 KK 发送给鲍勃,并删除了自己保存的副本。爱丽丝很聪明。真的,请向爱丽丝学习。

鲍勃意识到,只要密钥保持秘密,加密消息就是安全的。因此,他在存储前对密钥进行了随机置换。鲍勃认为,这样一来,即使伊芙同时获得了加密消息和密钥,也无法还原原始消息。鲍勃并不聪明。请不要学鲍勃。

在上述例子中,鲍勃可能选取了置换 (3, 4, 1, 2)(3,\,4,\,1,\,2),从而存储了置换后的密钥 P=(6, 3, 16, 7)P = (6,\,3,\,16,\,7)。

一年过去了,爱丽丝想要解密她的消息。直到此时,鲍勃才意识到这已不可能。由于他随机置换了密钥,该消息已永远丢失。我们之前是否提到过:鲍勃并不聪明?

鲍勃希望能从消息中挽回至少部分信息。由于他不够聪明,便向你求助。你已知加密消息 AA 和置换后的密钥 PP。那么,能够产生给定加密文本的字典序最小的原始消息是什么?

更准确地说:给定 AA 和 PP,找出字典序最小的消息 OO,使得存在某个置换 π\pi,满足对每个 ii 都有 。

注意:序列 SS 字典序小于序列 TT,当且仅当存在某个下标 ii,使得 Si<TiS_i < T_i,且对所有 j<ij < i 均有 Sj=TjS_j = T_j。

输入格式

The first line contains a single integer N (1 ≤ N ≤ 300000), the length of the message.

The second line contains N integers _A_1, _A_2, ..., A__N (0 ≤ A__i < 230) representing the encrypted message.

The third line contains N integers _P_1, _P_2, ..., P__N (0 ≤ P__i < 230) representing the permuted encryption key.

第一行包含一个整数 NN(1≤N≤3000001 \leq N \leq 300000),表示消息的长度。

第二行包含 NN 个整数 A1, A2, ..., ANA_1,\ A_2,\ ..., \ A_N(0≤Ai<2300 \leq A_i < 2^{30}),表示加密后的消息。

第三行包含 NN 个整数 P1, P2, ..., PNP_1,\ P_2,\ ..., \ P_N(0≤Pi<2300 \leq P_i < 2^{30}),表示置换后的加密密钥。

输出格式

Output a single line with N integers, the lexicographically smallest possible message O. Note that all its elements should be non-negative.

输出一行,包含 N 个整数,即字典序最小的可能消息 O。注意,其所有元素均应为非负数。

输入输出样例

  • 输入#1

    3
    8 4 13
    17 2 7

    输出#1

    10 3 28
  • 输入#2

    5
    12 7 87 22 11
    18 39 9 12 16

    输出#2

    0 14 69 6 44
  • 输入#3

    10
    331415699 278745619 998190004 423175621 42983144 166555524 843586353 802130100 337889448 685310951
    226011312 266003835 342809544 504667531 529814910 684873393 817026985 844010788 993949858 1031395667

    输出#3

    128965467 243912600 4281110 112029883 223689619 76924724 429589 119397893 613490433 362863284

说明/提示

In the first case, the solution is (10, 3, 28), since , and . Other possible permutations of key yield messages (25, 6, 10), (25, 3, 15), (10, 21, 10), (15, 21, 15) and (15, 6, 28), which are all lexicographically larger than the solution.

在第一种情况下,解为 (10, 3, 28)(10,\,3,\,28),因为 、 且 。其余可能的密钥排列所生成的消息为 (25, 6, 10)(25,\,6,\,10)、(25, 3, 15)(25,\,3,\,15)、(10, 21, 10)(10,\,21,\,10)、(15, 21, 15)(15,\,21,\,15) 和 (15, 6, 28)(15,\,6,\,28),它们均按字典序大于该解。

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

首页