#P9127. [USACO23FEB] Equal Sum Subarrays G

[USACO23FEB] Equal Sum Subarrays G

题目描述

Note: The time limit for this problem is 3s, 1.5x the default.

FJ gave Bessie an array aa of length N(2N500,1015ai1015)N(2 \le N \le 500,−10^{15} \le a_i \le 10^{15}) with all N(N+1)2\dfrac{N(N+1)}{2} contiguous subarray sums distinct. For each index i[1,N]i \in [1,N], help Bessie compute the minimum amount it suffices to change ai by so that there are two different contiguous subarrays of a with equal sum.

输入格式

The first line contains NN.

The next line contains a1,,aNa_1, \cdots ,a_N (the elements of aa, in order).

输出格式

One line for each index i[1,N]i \in [1,N].

题目大意

题目描述

提示:本题的时间限制是3s,为默认值的1.5倍。

FJ给了Bessie一个长度为 N(2N500,1015ai1015)N(2\leq N\leq 500, -10^{15}\leq a_i \leq 10^{15}) 的数组,且数组所有的 N(N+1)2\frac{N(N+1)}{2} 个区间和互不相同。对于每个 i[1,N]i\in[1,N],帮助Bessie把 aia_i 改成一个值,使得数组有两个区间和相等,且改值与 aia_i 的差值最小。

输入格式

第一行输入 NN

第二行输入数组 aa

输出格式

对于每个 i[1,N]i\in[1,N],每行输出满足题意的最小差值。

说明/提示

样例1:把 a1a_122 使得 a1+a2=a2a_1+a_2=a_2。类似的,把 a2a_233 使得 a1+a2=a1a_1+a_2=a_1

样例2:把 a1a_111 或把 a3a_311 使得 a1=a3a_1=a_3。把 a2a_266 使得 a1=a1+a2+a3a_1=a_1+a_2+a_3

数据范围

输入 33N40N\leq 40

输入 44N80N\leq 80

输入 575-7N200N\leq 200

输入 8168-16:没有额外限制。

2
2 -3
2
3
3
3 -10 4
1
6
1

提示

Explanation for Sample 1

Decreasing a1a_1 by 22 would result in a1+a2=a2a_1+a_2=a_2. Similarly, increasing a2a_2 by 33 would result in a1+a2=a1a_1+a_2=a_1.

Explanation for Sample 2

Increasing a1 or decreasing a3a_3 by 11 would result in a1=a3a_1=a_3. Increasing a2a_2 by 66 would result in a1=a1+a2+a3a_1=a_1+a_2+a_3.

SCORING

  • Input 33: N40N \le 40
  • Input 44: N80N \le 80
  • Inputs 575-7: N200N \le 200
  • Inputs 8-16: No additional constraints.