結果
問題 | No.1300 Sum of Inversions |
ユーザー | ayaoni |
提出日時 | 2020-11-27 23:40:50 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,351 ms / 2,000 ms |
コード長 | 1,905 bytes |
コンパイル時間 | 310 ms |
コンパイル使用メモリ | 87,256 KB |
実行使用メモリ | 190,216 KB |
最終ジャッジ日時 | 2023-10-10 21:49:58 |
合計ジャッジ時間 | 34,689 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 75 ms
71,324 KB |
testcase_01 | AC | 75 ms
71,616 KB |
testcase_02 | AC | 72 ms
71,496 KB |
testcase_03 | AC | 1,036 ms
159,404 KB |
testcase_04 | AC | 1,030 ms
157,108 KB |
testcase_05 | AC | 849 ms
135,300 KB |
testcase_06 | AC | 1,197 ms
175,224 KB |
testcase_07 | AC | 1,161 ms
171,892 KB |
testcase_08 | AC | 1,265 ms
180,616 KB |
testcase_09 | AC | 1,261 ms
180,944 KB |
testcase_10 | AC | 715 ms
125,644 KB |
testcase_11 | AC | 729 ms
126,612 KB |
testcase_12 | AC | 1,058 ms
159,044 KB |
testcase_13 | AC | 1,018 ms
155,944 KB |
testcase_14 | AC | 1,351 ms
190,216 KB |
testcase_15 | AC | 1,236 ms
179,572 KB |
testcase_16 | AC | 1,074 ms
160,624 KB |
testcase_17 | AC | 687 ms
124,204 KB |
testcase_18 | AC | 763 ms
130,776 KB |
testcase_19 | AC | 903 ms
144,636 KB |
testcase_20 | AC | 946 ms
146,616 KB |
testcase_21 | AC | 918 ms
147,268 KB |
testcase_22 | AC | 834 ms
135,796 KB |
testcase_23 | AC | 1,186 ms
176,428 KB |
testcase_24 | AC | 851 ms
135,824 KB |
testcase_25 | AC | 742 ms
129,148 KB |
testcase_26 | AC | 751 ms
129,212 KB |
testcase_27 | AC | 822 ms
133,604 KB |
testcase_28 | AC | 1,277 ms
187,588 KB |
testcase_29 | AC | 930 ms
147,764 KB |
testcase_30 | AC | 1,180 ms
179,000 KB |
testcase_31 | AC | 817 ms
135,900 KB |
testcase_32 | AC | 838 ms
137,080 KB |
testcase_33 | AC | 431 ms
118,908 KB |
testcase_34 | AC | 452 ms
130,524 KB |
testcase_35 | AC | 667 ms
150,784 KB |
testcase_36 | AC | 706 ms
175,932 KB |
ソースコード
import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) class SegTree: # モノイドに対して適用可能、Nが2冪でなくても良い def __init__(self,N,seg_func,unit): self.N = 1 << (N-1).bit_length() self.func = seg_func self.unit = unit self.tree = [self.unit]*(2*self.N) def set_val(self,i,x): # i番目(0-index)の値をxに変更 i += self.N self.tree[i] = x i >>= 1 while i: self.tree[i] = self.func(self.tree[i << 1],self.tree[i << 1 | 1]) i >>= 1 def fold(self,L,R): # [L,R)の区間取得 L += self.N R += self.N vL = self.unit vR = self.unit while L < R: if L & 1: vL = self.func(vL,self.tree[L]) L += 1 if R & 1: R -= 1 vR = self.func(self.tree[R],vR) L >>= 1 R >>= 1 return self.func(vL,vR) def seg_func(x,y): x0,x1 = x y0,y1 = y return ((x0+y0) % mod,(x1+y1) % mod) N = I() A = LI() mod = 998244353 AA = sorted(list(set(A))) d = {} M = len(AA) for i in range(M): d[AA[i]] = i ST_left = SegTree(N,seg_func,(0,0)) X_left = [] for i in range(N): a = d[A[i]] ST_left.set_val(a,seg_func((A[i],1),ST_left.tree[a+ST_left.N])) if 1 <= i <= N-2: X_left.append(ST_left.fold(a+1,N)) ST_right = SegTree(N,seg_func,(0,0)) X_right = [] for i in range(N-1,-1,-1): a = d[A[i]] ST_right.set_val(a,seg_func((A[i],1),ST_right.tree[a+ST_right.N])) if 1 <= i <= N-2: X_right.append(ST_right.fold(0,a)) X_right.reverse() ans = 0 for i in range(1,N-1): a = A[i] x,y = X_left[i-1] z,w = X_right[i-1] if y > 0 and w > 0: ans += a*(y*w)+w*x+y*z ans %= mod print(ans)