社区讨论

题目TeX修复

CF1988E Range Minimum Sum参与者 2已保存回复 1

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
1 条
当前快照
1 份
快照标识符
@lynokc7l
此快照首次捕获于
2024/07/16 08:33
2 年前
此快照最后确认于
2024/07/16 08:54
2 年前
查看原帖

Range Minimum Sum

题目描述

For an array [a1,a2,,an][a_1,a_2,\ldots,a_n] of length nn , define f(a)f(a) as the sum of the minimum element over all subsegments. That is, f(a)=l=1nr=lnminlirai.f(a)=\sum_{l=1}^n\sum_{r=l}^n \min_{l\le i\le r}a_i.
A permutation is a sequence of integers from 11 to nn of length nn containing each number exactly once. You are given a permutation [a1,a2,,an][a_1,a_2,\ldots,a_n] . For each ii , solve the following problem independently:
Erase aia_i from aa , concatenating the remaining parts, resulting in b=[a1,a2,,ai1,;ai+1,,an]b = [a_1,a_2,\ldots,a_{i-1},\\;a_{i+1},\ldots,a_{n}] .
Calculate f(b) f(b).

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t1051 \le t \le 10^5 ). Description of the test cases follows.
The first line of each test case contains an integer nn ( 1n51051\le n\le 5\cdot 10^5 ).
The second line of each test case contains nn distinct integers a1,,ana_1,\ldots,a_n ( 1ain1\le a_i\le n ).
It is guaranteed that the sum of nn over all test cases does not exceed 10610^6 .

输出格式

For each test case, print one line containing nn integers. The ii -th integer should be the answer when erasing aia_i .

样例 #1

样例输入 #1

CPP
4
1
1
3
3 1 2
5
4 2 1 5 3
8
8 1 4 6 7 3 5 2

样例输出 #1

CPP
0 
4 7 5 
19 21 27 17 19 
79 100 72 68 67 80 73 80

提示

In the second test case, a=[3,1,2]a=[3,1,2] .
  • When removing a1a_1 , b=[1,2]b=[1,2] . f(b)=1+2+min{1,2}=4f(b)=1+2+\min\{1,2\}=4 .
  • When removing a2a_2 , b=[3,2]b=[3,2] . f(b)=3+2+min{3,2}=7f(b)=3+2+\min\{3,2\}=7 .
  • When removing a3a_3 , b=[3,1]b=[3,1] . f(b)=3+1+min{3,1}=5f(b)=3+1+\min\{3,1\}=5 .

回复

1 条回复,欢迎继续交流。

正在加载回复...