CF923C.Perfect Security

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Alice has a very important message MM 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 KK 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 AA . Alice is smart. Be like Alice.

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

Alice realised that she cannot store the key with the encrypted message. Alice sent her key KK 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)(3,4,1,2) and stored the permuted key P=(6,3,16,7)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 AA and the permuted key PP . What is the lexicographically smallest message that could have resulted in the given encrypted text?

More precisely, for given AA and PP , find the lexicographically smallest message OO , for which there exists a permutation ππ such that for every ii .

Note that the sequence SS is lexicographically smaller than the sequence TT , if there is an index ii such that S_{i}<T_{i} and for all j<i the condition Sj=TjS_{j}=T_{j} holds.

输入格式

The first line contains a single integer NN ( 1<=N<=3000001<=N<=300000 ), the length of the message.

The second line contains NN integers A1,A2,...,ANA_{1},A_{2},...,A_{N} ( 0<=A_{i}<2^{30} ) representing the encrypted message.

The third line contains NN integers P1,P2,...,PNP_{1},P_{2},...,P_{N} ( 0<=P_{i}<2^{30} ) representing the permuted encryption key.

输出格式

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

输入输出样例

  • 输入#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)(10,3,28) , since , and . Other possible permutations of key yield messages (25,6,10)(25,6,10) , (25,3,15)(25,3,15) , (10,21,10)(10,21,10) , (15,21,15)(15,21,15) and (15,6,28)(15,6,28) , which are all lexicographically larger than the solution.

首页