結果

問題 No.1975 Zigzag Sequence
ユーザー ニックネームニックネーム
提出日時 2022-06-10 23:27:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,188 bytes
コンパイル時間 409 ms
コンパイル使用メモリ 11,908 KB
実行使用メモリ 62,956 KB
最終ジャッジ日時 2023-10-21 05:48:05
合計ジャッジ時間 48,669 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,268 KB
testcase_01 AC 31 ms
10,268 KB
testcase_02 AC 31 ms
10,268 KB
testcase_03 AC 219 ms
14,904 KB
testcase_04 AC 106 ms
12,140 KB
testcase_05 TLE -
testcase_06 AC 1,314 ms
35,284 KB
testcase_07 AC 240 ms
15,288 KB
testcase_08 AC 1,267 ms
31,420 KB
testcase_09 TLE -
testcase_10 AC 1,338 ms
34,304 KB
testcase_11 AC 1,552 ms
37,064 KB
testcase_12 AC 344 ms
16,492 KB
testcase_13 AC 32 ms
10,268 KB
testcase_14 AC 31 ms
10,268 KB
testcase_15 AC 32 ms
10,268 KB
testcase_16 AC 32 ms
10,268 KB
testcase_17 AC 32 ms
10,268 KB
testcase_18 AC 1,460 ms
25,672 KB
testcase_19 AC 1,458 ms
25,672 KB
testcase_20 TLE -
testcase_21 AC 1,874 ms
43,896 KB
testcase_22 AC 1,913 ms
56,884 KB
testcase_23 AC 1,906 ms
56,884 KB
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 AC 1,533 ms
32,008 KB
testcase_33 AC 1,534 ms
32,008 KB
testcase_34 TLE -
testcase_35 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

class BinaryIndexedTree:
    def __init__(self, n, mod):
        self.size = n
        self.tree = [0]*(n+1)
        self.mod = mod
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = (self.tree[i]+x)%self.mod
            i += i&-i
    def sum(self, i):
        s = 0
        while i > 0:
            s = (s+self.tree[i])%self.mod
            i -= i&-i
        return s
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
itov = sorted(set(a))
vtoi = {v: i for i, v in enumerate(itov)}
b = [vtoi[v]+1 for v in a]
r = [pow(2, i, mod) for i in range(n)]
ldans = [0]*n
luans = [0]*n
ldbit = BinaryIndexedTree(n, mod)
lubit = BinaryIndexedTree(n, mod)
rdans = [0]*n
ruans = [0]*n
rdbit = BinaryIndexedTree(n, mod)
rubit = BinaryIndexedTree(n, mod)
ans = 0
for i, v in enumerate(b):
    ldans[i] = ldbit.sum(v-1)
    luans[i] = lubit.sum(n-v)
    ldbit.add(v, r[i])
    lubit.add(n+1-v, r[i])
for i, v in enumerate(b[::-1]):
    rdans[i] = rdbit.sum(v-1)
    ruans[i] = rubit.sum(n-v)
    rdbit.add(v, r[i])
    rubit.add(n+1-v, r[i])
for i in range(n):
    ans = (ans+ldans[i]*rdans[n-1-i])%mod
    ans = (ans+luans[i]*ruans[n-1-i])%mod
print(ans)
0