結果
問題 | No.1975 Zigzag Sequence |
ユーザー | mkawa2 |
提出日時 | 2023-02-23 07:57:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 718 ms / 2,000 ms |
コード長 | 1,876 bytes |
コンパイル時間 | 551 ms |
コンパイル使用メモリ | 87,204 KB |
実行使用メモリ | 106,320 KB |
最終ジャッジ日時 | 2023-09-30 11:44:03 |
合計ジャッジ時間 | 17,721 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 72 ms
71,408 KB |
testcase_01 | AC | 71 ms
71,260 KB |
testcase_02 | AC | 71 ms
71,152 KB |
testcase_03 | AC | 166 ms
80,156 KB |
testcase_04 | AC | 159 ms
80,176 KB |
testcase_05 | AC | 668 ms
99,836 KB |
testcase_06 | AC | 444 ms
91,496 KB |
testcase_07 | AC | 170 ms
79,944 KB |
testcase_08 | AC | 460 ms
93,568 KB |
testcase_09 | AC | 621 ms
98,596 KB |
testcase_10 | AC | 450 ms
91,916 KB |
testcase_11 | AC | 493 ms
93,760 KB |
testcase_12 | AC | 194 ms
81,068 KB |
testcase_13 | AC | 69 ms
71,408 KB |
testcase_14 | AC | 70 ms
71,408 KB |
testcase_15 | AC | 69 ms
71,268 KB |
testcase_16 | AC | 70 ms
71,152 KB |
testcase_17 | AC | 71 ms
71,260 KB |
testcase_18 | AC | 208 ms
105,308 KB |
testcase_19 | AC | 205 ms
105,468 KB |
testcase_20 | AC | 525 ms
106,164 KB |
testcase_21 | AC | 517 ms
106,056 KB |
testcase_22 | AC | 388 ms
99,492 KB |
testcase_23 | AC | 396 ms
99,704 KB |
testcase_24 | AC | 515 ms
99,432 KB |
testcase_25 | AC | 512 ms
99,444 KB |
testcase_26 | AC | 716 ms
100,236 KB |
testcase_27 | AC | 718 ms
101,436 KB |
testcase_28 | AC | 481 ms
99,232 KB |
testcase_29 | AC | 478 ms
99,352 KB |
testcase_30 | AC | 477 ms
100,576 KB |
testcase_31 | AC | 482 ms
100,320 KB |
testcase_32 | AC | 390 ms
106,320 KB |
testcase_33 | AC | 383 ms
106,260 KB |
testcase_34 | AC | 695 ms
100,180 KB |
testcase_35 | AC | 684 ms
100,188 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = (1 << 63)-1 # inf = (1 << 31)-1 md = 10**9+7 # md = 998244353 class BitSum: def __init__(self, n): self.n = n+1 self.table = [0]*self.n self.aa = [0]*n def __getitem__(self, item): return self.aa[item] def add(self, i, x): self.aa[i] += x i += 1 while i < self.n: self.table[i] += x i += i & -i def sum(self, i): i += 1 res = 0 while i > 0: res += self.table[i] i -= i & -i return res def sumlr(self, l, r): if l >= r: return 0 if l == 0: return self.sum(r-1) return self.sum(r-1)-self.sum(l-1) def solve(): res = 0 ia = sorted(enumerate(aa), key=lambda x: x[1]) ll, rr = BitSum(n), BitSum(n) pend = [] for i, a in ia: if pend and pend[0][1] != a: for j, _ in pend: ll.add(j, pow(2, j, md)) j = n-1-j rr.add(j, pow(2, j, md)) pend.clear() res += ll.sum(i)*rr.sum(n-1-i)%md res %= md pend.append((i, a)) return res n = II() aa = LI() ans = solve() aa = [-a for a in aa] ans += solve() print(ans%md)