結果
問題 | No.1300 Sum of Inversions |
ユーザー | terasa |
提出日時 | 2022-08-16 19:32:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,274 ms / 2,000 ms |
コード長 | 1,912 bytes |
コンパイル時間 | 185 ms |
コンパイル使用メモリ | 82,280 KB |
実行使用メモリ | 135,496 KB |
最終ジャッジ日時 | 2024-10-03 12:01:57 |
合計ジャッジ時間 | 33,142 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 56 ms
65,152 KB |
testcase_01 | AC | 56 ms
64,640 KB |
testcase_02 | AC | 52 ms
65,024 KB |
testcase_03 | AC | 1,075 ms
123,392 KB |
testcase_04 | AC | 1,032 ms
122,356 KB |
testcase_05 | AC | 805 ms
115,968 KB |
testcase_06 | AC | 1,143 ms
130,152 KB |
testcase_07 | AC | 1,044 ms
125,812 KB |
testcase_08 | AC | 1,167 ms
132,232 KB |
testcase_09 | AC | 1,190 ms
131,704 KB |
testcase_10 | AC | 651 ms
107,136 KB |
testcase_11 | AC | 668 ms
108,032 KB |
testcase_12 | AC | 982 ms
123,008 KB |
testcase_13 | AC | 911 ms
121,816 KB |
testcase_14 | AC | 1,274 ms
135,496 KB |
testcase_15 | AC | 1,170 ms
130,772 KB |
testcase_16 | AC | 993 ms
123,688 KB |
testcase_17 | AC | 658 ms
105,312 KB |
testcase_18 | AC | 729 ms
110,848 KB |
testcase_19 | AC | 837 ms
116,256 KB |
testcase_20 | AC | 872 ms
117,628 KB |
testcase_21 | AC | 850 ms
119,584 KB |
testcase_22 | AC | 784 ms
115,004 KB |
testcase_23 | AC | 1,144 ms
129,816 KB |
testcase_24 | AC | 811 ms
116,096 KB |
testcase_25 | AC | 693 ms
109,184 KB |
testcase_26 | AC | 700 ms
108,928 KB |
testcase_27 | AC | 794 ms
114,048 KB |
testcase_28 | AC | 1,228 ms
133,564 KB |
testcase_29 | AC | 860 ms
118,760 KB |
testcase_30 | AC | 1,173 ms
131,504 KB |
testcase_31 | AC | 816 ms
116,660 KB |
testcase_32 | AC | 846 ms
117,760 KB |
testcase_33 | AC | 477 ms
128,660 KB |
testcase_34 | AC | 496 ms
134,108 KB |
testcase_35 | AC | 499 ms
130,104 KB |
testcase_36 | AC | 500 ms
134,140 KB |
ソースコード
import sys import pypyjit import itertools import heapq import math from collections import deque, defaultdict import bisect import string input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) pypyjit.set_param('max_unroll_recursion=-1') def index_lt(a, x): 'return largest index s.t. A[i] < x or -1 if it does not exist' return bisect.bisect_left(a, x) - 1 def index_le(a, x): 'return largest index s.t. A[i] <= x or -1 if it does not exist' return bisect.bisect_right(a, x) - 1 def index_gt(a, x): 'return smallest index s.t. A[i] > x or len(a) if it does not exist' return bisect.bisect_right(a, x) def index_ge(a, x): 'return smallest index s.t. A[i] >= x or len(a) if it does not exist' return bisect.bisect_left(a, x) class BIT: # 0-indexed def __init__(self, N): self.N = N self.X = [0] * (N + 1) def add(self, i, x): i += 1 while i <= self.N: self.X[i] += x self.X[i] %= mod i += i & -i def sum(self, i): s = 0 while i > 0: s += self.X[i] s %= mod i -= i & -i return s def range_sum(self, l, r): return self.sum(r) - self.sum(l) N = int(input()) A = list(map(int, input().split())) mod = 998244353 brn = BIT(N) brs = BIT(N) bln = BIT(N) bls = BIT(N) R = [0] * N Sr = [0] * N L = [0] * N Sl = [0] * N B = [(i, A[i]) for i in range(N)] B.sort(key=lambda x: x[1]) for i, a in B: brn.add(i, 1) brs.add(i, a) R[i] = brn.range_sum(i + 1, N) Sr[i] = brs.range_sum(i + 1, N) B.sort(key=lambda x: x[0], reverse=True) B.sort(key=lambda x: x[1], reverse=True) for i, a in B: bln.add(i, 1) bls.add(i, a) L[i] = bln.range_sum(0, i) Sl[i] = bls.range_sum(0, i) ans = 0 for i in range(N): ans += R[i] * Sl[i] + L[i] * Sr[i] + A[i] * R[i] * L[i] ans %= mod print(ans)