No.1919 Many Monster Battles
タグ : / 解いたユーザー数 23
作問者 :
とりゐ
/ テスター :
riano
Problem Statement
There is an $N\times N$ grid, and Alice and Bob each keep one monster in every cell. The power of Alice's monster in cell $(i,j)$ is $A_{i,j}$, which equals $|a_i-a_j|$, and the power of Bob's monster is $B_{i,j}$, which equals $|b_i-b_j|$.
A battle took place in each of the $N^2$ cells, and the result of the battle in cell $(i,j)$ was as follows.
- If $A_{i,j}\gt B_{i,j}$, Bob's monster in cell $(i,j)$ disappears.
- If $A_{i,j}= B_{i,j}$, both Alice's and Bob's monsters in cell $(i,j)$ disappear.
- If $A_{i,j}\lt B_{i,j}$, Alice's monster in cell $(i,j)$ disappears.
Input
$N$ $a_1$ $a_2$ $\ldots$ $a_N$ $b_1$ $b_2$ $\ldots$ $b_N$
- $2\leq N\leq 2\times 10^5$
- $1\leq a_i,b_i\leq 10^9$
- All inputs are integers.
Output
Output the sum of the powers of Alice's remaining monsters and the sum of the powers of Bob's remaining monsters after the battles, in this order, each modulo $10^9+7$.
Sample
Sample 1
Input
3 1 4 5 2 5 3
Output
8 4
The powers of the monsters in each cell before the battles are as follows (the left side shows the powers of Alice's monsters, and the right side shows the powers of Bob's monsters).
0 3 4 0 3 1 3 0 1 3 0 2 4 1 0 1 2 0The powers of the monsters in each cell after the battles are as follows (monsters that disappeared are represented by
-).
- - 4 - - - - - - - - 2 4 - - - 2 -Therefore, the sum of the powers of Alice's remaining monsters after the battles is $8$, and the sum of the powers of Bob's remaining monsters is $4$.
Sample 2
Input
4 1 2 3 4 5 6 7 8
Output
0 0
All monsters disappear.
Sample 3
Input
5 700000000 200000000 800000000 600000000 100000000 700000000 800000000 100000000 300000000 900000000
Output
199999986 199999951
Output the values modulo $10^9+7$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。