#D. 线段seg

    Type: Default File IO: seg 5000ms 512MiB

线段seg

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

题目描述

nn 个整数 x1,x2,,xnx_1, x_2, \dots , x_n

另外还有 nn 个正整数 a1,a2,,ana_1, a_2, \dots , a_n

令排列 P=(p1,p2,,pn)P=(p_1,p_2,\dots , p_n)

初始,整条数轴都是白色的。

对于每个 ii,给线段 [xiapi,xi+apix_i-a_{p_i}, x_i+a_{p_i}]染成黑色。

如染色线段为 [1,3], [2,4], [6,7] 那么黑色长度为 41+76=44-1+7-6=4

f(P)f(P) 为黑色的总长度。

对于每个排列 PP,求出 f(P)f(P) 之和。

输入格式

第一行一个整数 nn

第二行 nn 个整数 xix_i

第三行 nn 个整数 aia_i

输出格式

输出一个整数,表示 f(P)f(P) 之和 模 109+710^9+7

3
2 6 15
1 2 4
78
1
1
7
14
4
7 2 7 2
3 2 1 2
240
7
1 1 2 9 17 26 30
4 4 4 4 4 4 4
181440
11
257869734 -413759255 671386528 312442221 -479133479 837936940 -775252592 -785229024 -306462979 685409332 62181930
987323333 202379759 242380132 464003610 240120482 288801746 7692451 552912477 795257073 629515685 667287542
862900292
9
0 0 -2000 396 727 999 999 1300 2000
26 268 268 396 561 604 883 998 999
616426169

数据范围

对于所有数据 $ 1\le n \le 1500, -10^9\le x_i \le 10^9 , 1\le a_i \le 10^9$。

子任务1(7分): 所有 aia_i 相同。

子任务2(8分): n9,2000xi,ai2000n\le 9, -2000 \le x_i, a_i \le 2000

子任务3(31分):n300,105xi,ai105n\le 300, -10^5 \le x_i, a_i \le 10^5

子任务4(17分):n300n \le 300

子任务5(25分):105xi,ai105-10^5 \le x_i, a_i \le 10^5

子任务6(12分):

CSP-S模拟赛

Not Attended
Status
Done
Rule
OI
Problem
4
Start at
2023-10-17 8:00
End at
2023-10-17 12:00
Duration
4 hour(s)
Host
Partic.
25