結果

問題 No.1079 まお
ユーザー nehan_der_thalnehan_der_thal
提出日時 2020-06-12 22:53:41
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 889 bytes
コンパイル時間 401 ms
コンパイル使用メモリ 82,416 KB
実行使用メモリ 154,808 KB
最終ジャッジ日時 2024-06-24 05:39:25
合計ジャッジ時間 5,826 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys;input=sys.stdin.readline
from collections import defaultdict
n, k = map(int, input().split())
X = list(map(int, input().split()))
st_f = [(0, 10**18), (X[0], X[0])]
st_b = [(0, 10**18)]
r = 0
j = 1
C = defaultdict(int)
D = defaultdict(int)
C[X[0]] += 1
D[X[0]] += 1
for i in range(n):
    while j<n:
#        if j == n:
#            j += 1
#            break
        if min(st_f[-1][1], st_b[-1][1]) == X[j]:
            break
        C[X[j]] += j+1
        D[X[j]] += 1
        st_f.append(
                (X[j], min(st_f[-1][1], X[j]))
                )
        j += 1
    if len(st_b) == 1:
        while len(st_f) > 1:
            x, y = st_f.pop()
            st_b.append(
                    (x, min(st_b[-1][1], x))
                    )
    st_b.pop()
    r += C[k-X[i]] - D[k-X[i]]*i
#    print(i, j, C[k-X[i]], D[k-X[i]])
    C[X[i]] -= i+1
    D[X[i]] -= 1
print(r)
0