CF193B.Xor

普及+/提高

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

John Doe has four arrays: a, b, k, and p. Each array consists of n integers. Elements of all arrays are indexed starting from 1. Array p is a permutation of integers 1 to n.

John invented a game for his friends and himself. Initially a player is given array a. The player must consecutively execute exactly u operations on a. You are permitted to execute the following operations:

  • Operation 1: For each change a__i into . Expression means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in language C++ and Java it is marked as "^", in Pascal — as "xor".
  • Operation 2: For each change a__i into a__p__i + r. When this operation is executed, all changes are made at the same time.

After all u operations are applied, the number of points the player gets is determined by the formula .

John wants to find out what maximum number of points a player can win in his game. Help him.

约翰·多伊尔有四个数组:aa、bb、kk 和 pp。每个数组均包含 nn 个整数,所有数组的元素下标均从 1 开始。数组 pp 是整数 11 到 nn 的一个排列。

约翰为自己和朋友们发明了一个游戏。初始时,玩家获得数组 aa。玩家必须依次执行恰好 uu 次操作。允许执行以下两种操作:

  • 操作 1:对每个 1≤i≤n1 \le i \le n,将 aia_i 更新为 ai⊕kia_i \oplus k_i。其中表达式 x⊕yx \oplus y 表示对整数 xx 和 yy 执行按位异或(bitwise xor)运算。该运算在所有现代编程语言中均有实现,例如在 C++ 和 Java 中用符号 ^ 表示,在 Pascal 中用 xor 表示。
  • 操作 2:对每个 1≤i≤n1 \le i \le n,将 aia_i 更新为 api+ra_{p_i} + r。执行该操作时,所有更新需同时进行。

在完成全部 uu 次操作后,玩家所得分数由公式 ∑i=1nai⋅bi\sum_{i=1}^{n} a_i \cdot b_i 决定。

约翰希望知道玩家在该游戏中最多能获得多少分。请帮助他。

输入格式

The first line contains space-separated integers n, u and r (1 ≤ n, u ≤ 30, 0 ≤ r ≤ 100) — the number of elements in each array, the number of operations and the number that describes one of the operations.

Each of the next four lines contains n space-separated integers — arrays a, b, k, p. The first line has array a, the second line has array b, the third line has array k and the fourth one has array p.

It is guaranteed that elements of arrays a and b are positive and do not exceed 104 (1 ≤ a__i, b__i ≤ 104), elements of array k do not exceed 104 in the absolute value (|k| ≤ 104) and p is a permutation of numbers from 1 to n.

第一行包含三个以空格分隔的整数 nn、uu 和 rr(1 ≤ n, u ≤ 301 ≤ n, u ≤ 30,0 ≤ r ≤ 1000 ≤ r ≤ 100),分别表示每个数组的元素个数、操作次数,以及用于描述某一种操作的数字。

接下来的四行,每行包含 nn 个以空格分隔的整数,分别表示数组 aa、bb、kk、pp。第一行为数组 aa,第二行为数组 bb,第三行为数组 kk,第四行为数组 pp。

保证数组 aa 和 bb 的元素均为正整数且不超过 10410^4(即对所有 ii,满足 1 ≤ ai, bi ≤ 1041 ≤ a_i, b_i ≤ 10^4);数组 kk 的元素绝对值不超过 10410^4(即对所有 ii,满足 ∣ki∣ ≤ 104|k_i| ≤ 10^4);而 pp 是 11 到 nn 的一个排列。

输出格式

On a single line print number s — the maximum number of points that a player can win in John's game.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

在单行中输出整数 s —— 玩家在约翰的游戏中能获得的最大点数。

请注意,在 C++ 中读写 64 位整数时,请勿使用 %lld 说明符。推荐使用 cin、cout 流,或 %I64d 说明符。

输入输出样例

  • 输入#1

    3 2 1
    7 7 7
    8 8 8
    1 2 3
    1 3 2

    输出#1

    96
  • 输入#2

    2 1 0
    1 1
    1 1
    1 -1
    1 2

    输出#2

    0

说明/提示

In the first sample you should first apply the operation of the first type, then the operation of the second type.

在第一个样例中,你应该先执行第一种类型的操作,再执行第二种类型的操作。

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

首页