結果

問題 No.1975 Zigzag Sequence
ユーザー roarisroaris
提出日時 2022-06-16 21:37:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,213 bytes
コンパイル時間 411 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 106,120 KB
最終ジャッジ日時 2024-04-16 11:04:55
合計ジャッジ時間 12,576 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
53,504 KB
testcase_01 AC 48 ms
53,760 KB
testcase_02 AC 48 ms
53,888 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 WA -
testcase_14 AC 48 ms
53,760 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 46 ms
53,888 KB
testcase_18 AC 371 ms
98,304 KB
testcase_19 AC 365 ms
97,664 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 439 ms
104,948 KB
testcase_23 WA -
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import defaultdict
 
def compress(l):
    l = list(set(l))
    l.sort()
    idx = defaultdict(int)

    for i in range(len(l)):
        idx[l[i]] = i
    
    return idx

class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)
    
    def add(self, i, x):
        i += 1
        
        while i<=self.n:
            self.bit[i] += x
            self.bit[i] %= MOD
            i += i&(-i)

    def acc(self, i):
        s = 0
        
        while i>0:
            s += self.bit[i]
            i -= i&(-i)
        
        return s

N = int(input())
A = list(map(int, input().split()))
ans = 0
MOD = 10**9+7

pos = defaultdict(list)

for i in range(N):
    pos[A[i]].append(i)

ks = list(pos.keys())
ks.sort()
bit1 = BIT(N)
bit2 = BIT(N)

for k in ks:
    for p in pos[k]:
        l = bit1.acc(p)
        r = bit2.acc(N)-bit2.acc(p)
        ans += l*r%MOD
        ans %= MOD
    
    for p in pos[k]:
        bit1.add(p, pow(2, p, MOD))
        bit2.add(p, pow(2, N-1-p, MOD))
        l = pow(2, p, MOD)-1-bit1.acc(p)
        r = pow(2, N-p, MOD)-1-bit2.acc(N)+bit2.acc(p)
        ans += l*r%MOD
        ans %= MOD

print(ans)
0