結果

問題 No.1975 Zigzag Sequence
ユーザー titiatitia
提出日時 2022-06-13 01:55:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,853 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 12,064 KB
実行使用メモリ 40,804 KB
最終ジャッジ日時 2023-10-24 20:59:02
合計ジャッジ時間 35,474 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
14,100 KB
testcase_01 AC 63 ms
14,100 KB
testcase_02 AC 62 ms
14,100 KB
testcase_03 WA -
testcase_04 AC 115 ms
15,096 KB
testcase_05 AC 1,365 ms
25,048 KB
testcase_06 AC 1,047 ms
24,812 KB
testcase_07 WA -
testcase_08 AC 780 ms
20,604 KB
testcase_09 AC 1,419 ms
30,164 KB
testcase_10 AC 1,000 ms
23,724 KB
testcase_11 AC 1,110 ms
25,036 KB
testcase_12 WA -
testcase_13 AC 61 ms
14,100 KB
testcase_14 AC 61 ms
14,100 KB
testcase_15 AC 61 ms
14,164 KB
testcase_16 AC 61 ms
14,100 KB
testcase_17 AC 60 ms
14,100 KB
testcase_18 AC 375 ms
23,496 KB
testcase_19 AC 375 ms
23,496 KB
testcase_20 WA -
testcase_21 AC 1,318 ms
24,292 KB
testcase_22 AC 1,522 ms
39,432 KB
testcase_23 AC 1,529 ms
39,432 KB
testcase_24 WA -
testcase_25 AC 1,785 ms
39,792 KB
testcase_26 WA -
testcase_27 AC 1,797 ms
32,652 KB
testcase_28 WA -
testcase_29 AC 1,691 ms
40,804 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 1,455 ms
26,376 KB
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

mod=10**9+7

N=int(input())
A=list(map(int,input().split()))

def solve(A):
    A=list(A)

    S=sorted(set(A))
    D={S[i]:i+1 for i in range(len(S))}

    for i in range(N):
        A[i]=D[A[i]]

    # BIT(BIT-indexed tree)
    LEN=len(S)+1

    BIT=[0]*(LEN+1) # 1-indexedなtree. 配列BITの長さはLEN+1にしていることに注意。

    def update(v,w): # index vにwを加える
        while v<=LEN:
            BIT[v]+=w
            v+=(v&(-v)) # v&(-v)で、最も下の立っているビット. 自分を含む大きなノードへ. たとえばv=3→v=4

    def getvalue(v): # [1,v]の区間の和を求める
        ANS=0
        while v!=0:
            ANS+=BIT[v]
            v-=(v&(-v)) # 自分より小さい自分の和を構成するノードへ. たとえばv=14→v=12へ
        return ANS


    BIT2=[0]*(LEN+1) # 1-indexedなtree. 配列BITの長さはLEN+1にしていることに注意。

    def update2(v,w): # index vにwを加える
        while v<=LEN:
            BIT2[v]+=w
            v+=(v&(-v)) # v&(-v)で、最も下の立っているビット. 自分を含む大きなノードへ. たとえばv=3→v=4

    def getvalue2(v): # [1,v]の区間の和を求める
        ANS=0
        while v!=0:
            ANS+=BIT2[v]
            v-=(v&(-v)) # 自分より小さい自分の和を構成するノードへ. たとえばv=14→v=12へ
        return ANS

    POW2=[1]
    for i in range(10**5+10):
        POW2.append(POW2[-1]*2%mod)


    for i in range(N):
        a=A[i]
        update(a,POW2[i])

    ANS=0

    for i in range(N-1,-1,-1):
        a=A[i]
        ANS+=getvalue(a-1)*getvalue2(a-1)
        ANS%=mod

        update(a,-POW2[i])
        update2(a,POW2[N-1-i])

    return ANS


B=[10**10-a for a in A]
print(solve(tuple(A))+solve(tuple(B)))

    
0