import sys input = sys.stdin.readline from collections import deque def update(v,w): # index vにwを加える while v<=LEN: BIT[v]+=w v+=(v&(-v)) # v&(-v)で、最も下の立っているビット. 自分を含む大きなノードへ. たとえばv=3→v=4 def getvalue(v): # [1,v]の区間の和を求める ANS=0 while v!=0: ANS+=BIT[v] v-=(v&(-v)) # 自分より小さい自分の和を構成するノードへ. たとえばv=14→v=12へ return ANS T=int(input()) for tests in range(T): n=int(input()) P=list(map(int,input().split())) ANS=deque() LEN=n+1 BIT=[0]*(LEN+1) # 1-indexedなtree. 配列BITの長さはLEN+1にしていることに注意。 score=0 for i in range(n): p=P[i] x=getvalue(p) y=i-x if x