結果

問題 No.1371 交換門松列・松
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2020-11-13 12:27:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,746 bytes
コンパイル時間 1,051 ms
コンパイル使用メモリ 87,228 KB
実行使用メモリ 106,292 KB
最終ジャッジ日時 2023-09-30 02:01:56
合計ジャッジ時間 5,329 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
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 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3
import sys
import array

#https://yukicoder.me/submissions/385244 の移植
def add(bit,x,v):
    n=len(bit)
    while x<n:
        bit[x]+=v
        x+=x&-x


def acc(bit,x):
    a=0
    while x>0:
        a+=bit[x]
        x&=x-1
    return a

def bit_manip(n,points,queries,fstsgn,sndsgn):
    total=0
    acts=[None]*(len(points)+len(queries))
    pos=0
    for x,y in points:
        acts[pos]=(x*fstsgn,y*sndsgn,1)
        pos+=1
    for x,y in queries:
        acts[pos]=(x*fstsgn,y*sndsgn,0)
        pos+=1
    acts.sort()
    bit=array.array('l',[0])*(n+1)
    count=0
    for x,y,k in acts:
        if k:
            add(bit,y*sndsgn,1)
            count+=1
        else:
            if sndsgn==-1:
                total+=count-acc(bit,-y-1)
            else:
                total+=acc(bit,y)
    return total
                

def main():
    input=sys.stdin.readline
    n=int(input().rstrip())
    a=list(map(int,input().split()))

    if a[n-2]<a[n-1]:
        a.append(0)
    else:
        a.append(n+2)
    if a[0]<a[1]:
        a.append(n+2)
    else:
        a.append(0)
    downs=[]
    ups=[]
    lany=[]
    hany=[]
    for i in range(n):
        if a[i]<a[i+1]:
            #でこ
            b=min(a[i-1],a[i+1])
            downs.append((a[i],b))
            lany.append((b,a[i]))
        else:
            #ぼこ
            b=max(a[i-1],a[i+1])
            ups.append((a[i],b))
            hany.append((b,a[i]))
    total=0
    #WA ここで終了
    return
    #凹凹
    total+=bit_manip(n,downs,lany,1,-1)
    #凸凹
    total+=bit_manip(n,ups,lany,1,1)
    #凹凸
    total+=bit_manip(n,downs,hany,-1,-1)
    #凸凸
    total+=bit_manip(n,ups,hany,-1,1)

    print((total-n)//2)

main()
0