結果
問題 | No.1975 Zigzag Sequence |
ユーザー | tamato |
提出日時 | 2022-06-10 21:56:52 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,118 bytes |
コンパイル時間 | 197 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 124,672 KB |
最終ジャッジ日時 | 2024-09-21 06:15:46 |
合計ジャッジ時間 | 11,501 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
52,608 KB |
testcase_01 | AC | 45 ms
52,736 KB |
testcase_02 | AC | 45 ms
52,480 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 38 ms
52,480 KB |
testcase_14 | AC | 38 ms
52,608 KB |
testcase_15 | AC | 37 ms
52,480 KB |
testcase_16 | AC | 40 ms
52,608 KB |
testcase_17 | AC | 38 ms
52,608 KB |
testcase_18 | AC | 266 ms
97,280 KB |
testcase_19 | AC | 277 ms
97,488 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 360 ms
124,416 KB |
testcase_23 | AC | 372 ms
124,288 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
ソースコード
mod = 998244353 def main(): import sys input = sys.stdin.readline class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i def lower_bound(self, w): if w <= 0: return 0 x = 0 k = 1 << (self.size.bit_length() - 1) while k: if x + k <= self.size and self.tree[x + k] < w: w -= self.tree[x + k] x += k k >>= 1 return x + 1 N = int(input()) A = list(map(int, input().split())) A_unique = sorted(list(set(A))) I = {a: [] for a in A_unique} for i, a in enumerate(A): I[a].append(i + 1) ans = 0 # asc bit_left = Bit(N) bit_right = Bit(N) pow2 = [1] for i in range(1, N+1): bit_left.add(i, pow2[-1]) bit_right.add(N - i + 1, pow2[-1]) pow2.append((pow2[-1] * 2) % mod) for a in A_unique: for i in I[a]: bit_left.add(i, -pow2[i - 1]) bit_right.add(i, -pow2[N - i]) for i in I[a]: val_l = bit_left.sum(i) val_r = bit_right.sum(N) - bit_right.sum(i) ans = (ans + (val_l * val_r)%mod)%mod # desc bit_left = Bit(N) bit_right = Bit(N) pow2 = [1] for i in range(1, N + 1): bit_left.add(i, pow2[-1]) bit_right.add(N - i + 1, pow2[-1]) pow2.append((pow2[-1] * 2) % mod) for a in A_unique[::-1]: for i in I[a]: bit_left.add(i, -pow2[i - 1]) bit_right.add(i, -pow2[N - i]) for i in I[a]: val_l = bit_left.sum(i) val_r = bit_right.sum(N) - bit_right.sum(i) ans = (ans + (val_l * val_r) % mod) % mod print(ans) if __name__ == '__main__': main()