結果
問題 | No.1300 Sum of Inversions |
ユーザー | c-yan |
提出日時 | 2020-12-05 00:12:45 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 905 ms / 2,000 ms |
コード長 | 1,496 bytes |
コンパイル時間 | 367 ms |
コンパイル使用メモリ | 82,100 KB |
実行使用メモリ | 149,056 KB |
最終ジャッジ日時 | 2024-09-15 09:17:17 |
合計ジャッジ時間 | 23,785 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
54,076 KB |
testcase_01 | AC | 39 ms
52,620 KB |
testcase_02 | AC | 40 ms
53,936 KB |
testcase_03 | AC | 704 ms
132,640 KB |
testcase_04 | AC | 689 ms
132,484 KB |
testcase_05 | AC | 564 ms
128,148 KB |
testcase_06 | AC | 767 ms
132,960 KB |
testcase_07 | AC | 724 ms
137,848 KB |
testcase_08 | AC | 828 ms
134,188 KB |
testcase_09 | AC | 834 ms
132,160 KB |
testcase_10 | AC | 461 ms
136,472 KB |
testcase_11 | AC | 460 ms
136,440 KB |
testcase_12 | AC | 663 ms
132,944 KB |
testcase_13 | AC | 690 ms
131,604 KB |
testcase_14 | AC | 905 ms
148,168 KB |
testcase_15 | AC | 838 ms
132,444 KB |
testcase_16 | AC | 735 ms
133,068 KB |
testcase_17 | AC | 478 ms
130,812 KB |
testcase_18 | AC | 541 ms
131,376 KB |
testcase_19 | AC | 634 ms
125,756 KB |
testcase_20 | AC | 639 ms
126,500 KB |
testcase_21 | AC | 627 ms
126,484 KB |
testcase_22 | AC | 565 ms
128,948 KB |
testcase_23 | AC | 777 ms
133,028 KB |
testcase_24 | AC | 590 ms
124,664 KB |
testcase_25 | AC | 518 ms
137,400 KB |
testcase_26 | AC | 515 ms
137,008 KB |
testcase_27 | AC | 555 ms
132,252 KB |
testcase_28 | AC | 849 ms
142,192 KB |
testcase_29 | AC | 601 ms
126,708 KB |
testcase_30 | AC | 816 ms
132,552 KB |
testcase_31 | AC | 559 ms
128,908 KB |
testcase_32 | AC | 567 ms
125,152 KB |
testcase_33 | AC | 276 ms
110,388 KB |
testcase_34 | AC | 303 ms
115,932 KB |
testcase_35 | AC | 469 ms
135,464 KB |
testcase_36 | AC | 524 ms
149,056 KB |
ソースコード
def bit_add(bit, i, x): i += 1 n = len(bit) while i <= n: bit[i - 1] += x i += i & -i def bit_sum(bit, i): result = 0 i += 1 while i > 0: result += bit[i - 1] i -= i & -i return result def bit_query(bit, start, stop): return bit_sum(bit, stop - 1) - bit_sum(bit, start - 1) def bit_add_m(bit, i, x): i += 1 n = len(bit) while i <= n: bit[i - 1] += x bit[i - 1] %= m i += i & -i def bit_sum_m(bit, i): result = 0 i += 1 while i > 0: result += bit[i - 1] result %= m i -= i & -i return result def bit_query_m(bit, start, stop): return (bit_sum(bit, stop - 1) - bit_sum(bit, start - 1)) % m N, *A = map(int, open(0).read().split()) m = 998244353 to = {x: i for i, x in enumerate(sorted(set(x for x in A)))} n = len(to.keys()) lbitc = [0] * n rbitc = [0] * n lbits = [0] * n rbits = [0] * n for x in A[2:]: i = to[x] bit_add(rbitc, i, 1) bit_add_m(rbits, i, x) bit_add(lbitc, to[A[0]], 1) bit_add_m(lbits, to[A[0]], A[0]) result = 0 for i in range(1, N - 1): x = to[A[i]] y = bit_query(lbitc, x + 1, n) z = bit_query(rbitc, 0, x) result += bit_query_m(lbits, x + 1, n) * z result += A[i] * (y * z) result += bit_query_m(rbits, 0, x) * y result %= m bit_add(lbitc, x, 1) bit_add_m(lbits, x, A[i]) x = to[A[i + 1]] bit_add(rbitc, x, -1) bit_add_m(rbits, x, -A[i + 1]) print(result)