結果
問題 | No.1975 Zigzag Sequence |
ユーザー | tamato |
提出日時 | 2022-06-10 21:59:43 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 542 ms / 2,000 ms |
コード長 | 2,119 bytes |
コンパイル時間 | 247 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 124,672 KB |
最終ジャッジ日時 | 2024-09-21 06:17:34 |
合計ジャッジ時間 | 12,300 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
52,352 KB |
testcase_01 | AC | 47 ms
52,352 KB |
testcase_02 | AC | 46 ms
52,224 KB |
testcase_03 | AC | 148 ms
79,668 KB |
testcase_04 | AC | 112 ms
77,468 KB |
testcase_05 | AC | 361 ms
93,824 KB |
testcase_06 | AC | 301 ms
94,876 KB |
testcase_07 | AC | 137 ms
78,744 KB |
testcase_08 | AC | 299 ms
86,656 KB |
testcase_09 | AC | 455 ms
106,496 KB |
testcase_10 | AC | 300 ms
91,472 KB |
testcase_11 | AC | 310 ms
93,568 KB |
testcase_12 | AC | 137 ms
78,664 KB |
testcase_13 | AC | 39 ms
52,480 KB |
testcase_14 | AC | 45 ms
52,224 KB |
testcase_15 | AC | 39 ms
52,352 KB |
testcase_16 | AC | 39 ms
52,608 KB |
testcase_17 | AC | 42 ms
52,096 KB |
testcase_18 | AC | 292 ms
97,536 KB |
testcase_19 | AC | 289 ms
97,408 KB |
testcase_20 | AC | 362 ms
98,432 KB |
testcase_21 | AC | 369 ms
98,304 KB |
testcase_22 | AC | 409 ms
124,348 KB |
testcase_23 | AC | 376 ms
124,032 KB |
testcase_24 | AC | 438 ms
124,544 KB |
testcase_25 | AC | 441 ms
124,672 KB |
testcase_26 | AC | 374 ms
91,264 KB |
testcase_27 | AC | 542 ms
109,300 KB |
testcase_28 | AC | 481 ms
124,160 KB |
testcase_29 | AC | 461 ms
124,288 KB |
testcase_30 | AC | 426 ms
124,416 KB |
testcase_31 | AC | 437 ms
124,032 KB |
testcase_32 | AC | 314 ms
96,536 KB |
testcase_33 | AC | 325 ms
96,640 KB |
testcase_34 | AC | 393 ms
97,924 KB |
testcase_35 | AC | 366 ms
98,344 KB |
ソースコード
mod = 1000000007 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()