Sum of Characteristics

시간 제한4초메모리 제한2048 MB

요약
무작위 배열에서 모든 구간에 대해 모든 인덱스 쌍의 max(a_i+j, a_j+i) 최솟값을 더한 값을 구한다.
난이도

어려움10점 중 9점

유형
수학, 그리디, 완전 탐색
정답자
아직 제출이 없습니다

문제

You are given an array aa consisting of nn random integers from 11 to nn. For its subsegment \[ℓ,r]\[\ell, r], the characteristic is the value C(ℓ,r)=min⁡_ℓ≤i<j≤rmax⁡(a_i+j,a_j+i).C(\ell, r) = \min\limits\_{\ell \le i < j \le r} \max(a\_i + j, a\_j + i)\text{.}

Your task is to calculate ∑_ℓ=1n∑_r=ℓ+1nC(ℓ,r).\sum\limits\_{\ell = 1}^n \sum\_{r = \ell + 1}^n C(\ell, r)\text{.}

입력

The first line contains an integer tt (1≤t≤3⋅1051 \le t \le 3 \cdot 10^5), the number of test cases. The test cases follow.

The first line of each test case contains an integer nn, the size of the array (1≤n≤3⋅1051 \le n \le 3 \cdot 10^5). The next line contains the array itself: nn integers from 11 to nn, picked uniformly and independently by a pseudorandom number generator.

The sum of nn over all test cases does not exceed 3⋅1053 \cdot 10^5.

출력

For each test case, output a line with a single integer: the sum of characteristics over all the subsegments.

예제1

  1. 예제 1

    입력
    3
    2
    2 1
    5
    3 5 4 1 4
    6
    1 4 6 1 6 3
    
    예상 출력
    4
    72
    112