結果
問題 | No.1300 Sum of Inversions |
ユーザー | Shirotsume |
提出日時 | 2023-02-17 20:34:29 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,693 bytes |
コンパイル時間 | 350 ms |
コンパイル使用メモリ | 86,972 KB |
実行使用メモリ | 153,400 KB |
最終ジャッジ日時 | 2023-09-26 17:44:19 |
合計ジャッジ時間 | 30,987 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 94 ms
75,768 KB |
testcase_01 | AC | 94 ms
71,340 KB |
testcase_02 | AC | 98 ms
71,492 KB |
testcase_03 | TLE | - |
testcase_04 | TLE | - |
testcase_05 | AC | 1,920 ms
120,480 KB |
testcase_06 | TLE | - |
testcase_07 | TLE | - |
testcase_08 | TLE | - |
testcase_09 | TLE | - |
testcase_10 | AC | 1,602 ms
114,436 KB |
testcase_11 | AC | 1,612 ms
114,584 KB |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
ソースコード
import sys from collections import deque, Counter input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 class fenwick_tree(): n=1 data=[0 for i in range(n)] def __init__(self,N): self.n=N self.data=[0 for i in range(N)] def add(self,p,x): assert 0<=p<self.n,"0<=p<n,p={0},n={1}".format(p,self.n) p+=1 while(p<=self.n): self.data[p-1]+=x p += p&(-p) def sum(self,l,r): assert (0<=l and l<=r and r<=self.n),"0<=l<=r<=n,l={0},r={1},n={2}".format(l,r,self.n) return self.sum0(r)-self.sum0(l) def sum0(self,r): s=0 while(r>0): s+=self.data[r-1] r-=r&-r return s def __getitem__(self, p): if isinstance(p, int): return self.sum(p, p + 1) else: return self.sum(p.start, p.stop) def __setitem__(self, p, x): return self.add(p, x - self[p]) n = ii() a = li() sa = list(set(a)) A = [(sa[i], i) for i in range(len(sa))] A.sort() d = {} sn = len(A) for i in range(sn): d[A[i][0]] = i f1 = fenwick_tree(sn) c1 = fenwick_tree(sn) f2 = fenwick_tree(sn) c2 = fenwick_tree(sn) ans = 0 for i in range(n): f2[d[a[i]]] += a[i] f2[d[a[i]]] %= mod c2[d[a[i]]] += 1 for i in range(n): f2[d[a[i]]] -= a[i] f2[d[a[i]]] %= mod c2[d[a[i]]] -= 1 ans += f1[d[a[i]] + 1: sn] * c2[0:d[a[i]]] + f2[0:d[a[i]]] * c1[d[a[i]] + 1: sn] + c1[d[a[i]] + 1: sn] * c2[0:d[a[i]]] % mod * a[i] ans %= mod f1[d[a[i]]] += a[i] c1[d[a[i]]] += 1 print(ans)