問題一覧 > 通常問題

No.1919 Many Monster Battles

レベル : / AI推定難易度 : 2150 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 23
作問者 : とりゐ / テスター : riano Shirotsume
お気に入りにしたユーザー ProblemId : 7994 / 自分の提出
問題文最終更新日: 2022-04-25 23:35:44
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 341 (順位表) の他の問題:

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.
For each of Alice and Bob, find the sum of the powers of their monsters remaining on the grid after the battles, modulo $10^9+7$.

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 0
The 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もしくは右上の雲マークをクリックしてアカウントを作成してください。