結果
問題 | No.1300 Sum of Inversions |
ユーザー | terasa |
提出日時 | 2022-06-02 23:42:07 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,516 bytes |
コンパイル時間 | 214 ms |
コンパイル使用メモリ | 82,568 KB |
実行使用メモリ | 165,192 KB |
最終ジャッジ日時 | 2024-09-21 02:11:58 |
合計ジャッジ時間 | 52,736 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
55,296 KB |
testcase_01 | AC | 45 ms
55,168 KB |
testcase_02 | AC | 45 ms
55,296 KB |
testcase_03 | AC | 1,614 ms
144,208 KB |
testcase_04 | AC | 1,574 ms
134,320 KB |
testcase_05 | AC | 1,252 ms
124,544 KB |
testcase_06 | AC | 1,819 ms
153,064 KB |
testcase_07 | AC | 1,753 ms
149,544 KB |
testcase_08 | TLE | - |
testcase_09 | AC | 1,980 ms
157,056 KB |
testcase_10 | AC | 1,021 ms
115,584 KB |
testcase_11 | AC | 1,038 ms
116,592 KB |
testcase_12 | AC | 1,588 ms
134,556 KB |
testcase_13 | AC | 1,526 ms
133,524 KB |
testcase_14 | TLE | - |
testcase_15 | AC | 1,944 ms
156,464 KB |
testcase_16 | AC | 1,637 ms
145,348 KB |
testcase_17 | AC | 1,016 ms
116,096 KB |
testcase_18 | AC | 1,116 ms
120,632 KB |
testcase_19 | AC | 1,358 ms
127,732 KB |
testcase_20 | AC | 1,422 ms
129,316 KB |
testcase_21 | AC | 1,409 ms
128,488 KB |
testcase_22 | AC | 1,295 ms
124,692 KB |
testcase_23 | AC | 1,864 ms
152,604 KB |
testcase_24 | AC | 1,281 ms
125,876 KB |
testcase_25 | AC | 1,132 ms
119,040 KB |
testcase_26 | AC | 1,073 ms
118,152 KB |
testcase_27 | AC | 1,259 ms
123,976 KB |
testcase_28 | TLE | - |
testcase_29 | AC | 1,391 ms
128,312 KB |
testcase_30 | AC | 1,974 ms
157,012 KB |
testcase_31 | AC | 1,256 ms
124,800 KB |
testcase_32 | AC | 1,308 ms
126,976 KB |
testcase_33 | AC | 962 ms
122,496 KB |
testcase_34 | AC | 968 ms
121,740 KB |
testcase_35 | AC | 1,049 ms
136,184 KB |
testcase_36 | AC | 1,097 ms
153,336 KB |
ソースコード
import sys import pypyjit import itertools import heapq import math from collections import deque, defaultdict import bisect 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 SegTree: def __init__(self, N, func, e): self.N = N self.func = func self.X = [e] * (N << 1) self.e = e def build(self, seq): for i in range(self.N): self.X[self.N + i] = seq[i] for i in range(self.N)[::-1]: self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1]) def add(self, i, x): i += self.N self.X[i] += x while i > 1: i >>= 1 self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1]) def update(self, i, x): i += self.N self.X[i] = x while i > 1: i >>= 1 self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1]) def query(self, L, R): L += self.N R += self.N vL = self.e vR = self.e while L < R: if L & 1: vL = self.func(vL, self.X[L]) L += 1 if R & 1: R -= 1 vR = self.func(self.X[R], vR) L >>= 1 R >>= 1 return self.func(vL, vR) N = int(input()) A = list(map(int, input().split())) mod = 998_244_353 D = defaultdict(list) for i, a in enumerate(A): D[a].append(i) S = [0] * (N + 1) S[0] = A[0] for i in range(1, N): S[i] = S[i - 1] + A[i] def f(a, b): return ((a[0] + b[0], a[1] + b[1])) st = SegTree(N, f, (0, 0)) ans = 0 for k in sorted(D.keys()): for j, i in enumerate(D[k]): r, sr = st.query(i, N) _l, _sl = st.query(0, i) l, sl = i - _l, S[i] - _sl l -= j sl -= k * (j + 1) ans += sl * r ans += sr * l ans += k * r * l ans %= mod for i in D[k]: st.update(i, (1, k)) print(ans)