結果

問題 No.1965 Heavier
コンテスト
ユーザー kidodesu
提出日時 2026-07-19 17:33:41
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 134 ms / 2,000 ms
+ 517µs
コード長 992 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 238 ms
コンパイル使用メモリ 95,724 KB
実行使用メモリ 118,364 KB
最終ジャッジ日時 2026-07-19 17:33:53
合計ジャッジ時間 6,509 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from heapq import *
def main():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    i = ans = 0
    while i < n:
        j = i
        while j < n-1:
            if A[j]+B[j] < A[j+1]+B[j+1] and A[j]+B[j+1] < A[j+1]+B[j]:
                j += 1
            else:
                break
        c = j-i+1
        ans += c*(c-1)//2
        i = j+1
    return ans
    r = 0
    ans = 0
    hq0 = []
    hq0_ = []
    hq1 = []
    hq1_ = []
    for l in range(n):
        while l == r or (r < n and hq0[0] > -A[r]-B[r] and hq1[0] > -A[r]+B[r]):
            heappush(hq0, -A[r]-B[r])
            heappush(hq1, -A[r]+B[r])
            r += 1
        ans += r-l-1
        heappush(hq0, -A[l]-B[l])
        heappush(hq1, -A[l]+B[l])
        while hq0_ and hq0[0] == hq0_[0]:
            heappop(hq0)
            heappop(hq0_)
        while hq1_ and hq1[0] == hq1_[0]:
            heappop(hq1)
            heappop(hq1_)
    return ans

print(main())
0