AT_abc476_f.Chebyshev Cafe
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is a city represented by a grid with N rows and N columns. The cell at the i-th row from the top and j-th column from the left is denoted as cell (i,j). Each cell has one cafe.
You are planning a meeting. Among the participants, the number of people living in cell (i,j) is (Ai×Bj)modM. The travel cost for one participant living in cell (sr, sc) to go to the cafe at cell (tr, tc) is max(∣sr−tr∣, ∣sc−tc∣).
Let f(i,j) be the total travel cost incurred when gathering all the participants at the cafe at cell (i,j).
For each cell (i,j), find the following value, and output the bitwise XOR of these values over all cells.
- f(i,j)+(i−1)N+(j−1)
What is the bitwise XOR operation?
The bitwise XOR of non-negative integers A and B (denoted A⊕B) is defined as follows.
- The digit in the 2k's place (k≥0) of A⊕B written in binary is 1 if exactly one of the digits in the 2k's place of A and B written in binary is 1, and 0 otherwise.
For example, 3⊕5=6 (in binary: 011(2)⊕101(2)=110(2)).
More generally, the bitwise XOR of k non-negative integers p1,p2,p3,…,pk is defined as (…((p1⊕p2)⊕p3)⊕⋯⊕pk), and it can be proved that this does not depend on the order of p1,p2,p3,…,pk.
有一座由 N 行 N 列组成的网格表示的城市。从上往下第 i 行、从左往右第 j 列的格子记为格子 (i,j)。每个格子中均有一家咖啡馆。
你正在筹划一场会议。在所有参会者中,居住在格子 (i,j) 的人数为 (Ai×Bj)modM。一名居住在格子 (sr, sc) 的参会者前往位于格子 (tr, tc) 的咖啡馆的通行代价为 max(∣sr−tr∣, ∣sc−tc∣)。
令 f(i,j) 表示将所有参会者全部召集至格子 (i,j) 处的咖啡馆时所产生的总通行代价。
对每个格子 (i,j),计算如下值,并输出所有格子对应值的**按位异或(bitwise XOR)**结果:
- f(i,j)+(i−1)N+(j−1)
什么是按位异或(bitwise XOR)运算?
非负整数 A 与 B 的按位异或(记作 A⊕B)定义如下:
- 将 A⊕B 写成二进制后,其 2k 位(k≥0)上的数字为 1,当且仅当 A 和 B 的二进制表示中,该位上恰好有一个为 1;否则该位为 0。
例如,3⊕5=6(二进制:011(2)⊕101(2)=110(2))。
更一般地,k 个非负整数 p1,p2,p3,…,pk 的按位异或定义为 (…((p1⊕p2)⊕p3)⊕⋯⊕pk),且可以证明该结果与 p1,p2,p3,…,pk 的顺序无关。
输入格式
The input is given from Standard Input in the following format:
N M
A1 … AN
B1 … BN
输入从标准输入中按以下格式给出:
N M
A1 … AN
B1 … BN
输出格式
Output the answer.
输出答案。
输入输出样例
输入#1
4 19 2 3 1 1 3 4 4 10
输出#1
467
输入#2
6 67 1 6 9 2 3 1 1 10 3 7 2 2
输出#2
1021
输入#3
20 676767 60932 508200 22883 481150 426836 554098 276223 307959 133025 573906 17711 413230 274246 500277 524959 477728 546547 43099 324227 660187 552697 293978 246000 159233 213736 628198 394200 194076 618720 453035 615100 331522 669419 180856 530693 399531 223149 159334 102107 598633
输出#3
764668547
说明/提示
Sample 1 Explanation:
The number of participants living in each cell is as follows: 693381244812441111010.
For example, the value of f(1,2) is obtained as the sum 176 of the following 16 values:
- The total amount 6×1=6 paid by the 6 residents of cell (1,1), each of whom pays a travel cost of max(∣1−1∣, ∣1−2∣)=1
- The total amount 8×0=0 paid by the 8 residents of cell (1,2), each of whom pays a travel cost of max(∣1−1∣, ∣2−2∣)=0
- The total amount 8×1=8 paid by the 8 residents of cell (1,3), each of whom pays a travel cost of max(∣1−1∣, ∣3−2∣)=1
- The total amount 1×2=2 paid by the 1 resident of cell (1,4), each of whom pays a travel cost of max(∣1−1∣, ∣4−2∣)=2
- ⋮
- The total amount 3×3=9 paid by the 3 residents of cell (4,1), each of whom pays a travel cost of max(∣4−1∣, ∣1−2∣)=3
- The total amount 4×3=12 paid by the 4 residents of cell (4,2), each of whom pays a travel cost of max(∣4−1∣, ∣2−2∣)=3
- The total amount 4×3=12 paid by the 4 residents of cell (4,3), each of whom pays a travel cost of max(∣4−1∣, ∣3−2∣)=3
- The total amount 10×3=30 paid by the 10 residents of cell (4,4), each of whom pays a travel cost of max(∣4−1∣, ∣4−2∣)=3
The value of f(i,j) for each cell is as follows: 220199212255176140159215179136143201224182178218.
Constraints
- 1≤N≤1500
- 2≤M≤2×106
- 1≤Ai≤M−1 (1≤i≤N)
- 1≤Bj≤M−1 (1≤j≤N)
- All input values are integers.
样例 1 解释:
每个格子中居住的参与者人数如下:693381244812441111010。
例如,f(1,2) 的值为以下 16 项之和,结果为 176:
- 格子 (1,1) 中的 6 名居民每人需支付交通费用 max(∣1−1∣, ∣1−2∣)=1,共支付 6×1=6;
- 格子 (1,2) 中的 8 名居民每人需支付交通费用 max(∣1−1∣, ∣2−2∣)=0,共支付 8×0=0;
- 格子 (1,3) 中的 8 名居民每人需支付交通费用 max(∣1−1∣, ∣3−2∣)=1,共支付 8×1=8;
- 格子 (1,4) 中的 1 名居民需支付交通费用 max(∣1−1∣, ∣4−2∣)=2,共支付 1×2=2;
- ⋮
- 格子 (4,1) 中的 3 名居民每人需支付交通费用 max(∣4−1∣, ∣1−2∣)=3,共支付 3×3=9;
- 格子 (4,2) 中的 4 名居民每人需支付交通费用 max(∣4−1∣, ∣2−2∣)=3,共支付 4×3=12;
- 格子 (4,3) 中的 4 名居民每人需支付交通费用 max(∣4−1∣, ∣3−2∣)=3,共支付 4×3=12;
- 格子 (4,4) 中的 10 名居民每人需支付交通费用 max(∣4−1∣, ∣4−2∣)=3,共支付 10×3=30。
每个格子对应的 f(i,j) 值如下:220199212255176140159215179136143201224182178218。
约束条件
- 1≤N≤1500
- 2≤M≤2×106
- 1≤Ai≤M−1(1≤i≤N)
- 1≤Bj≤M−1(1≤j≤N)
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?