提出 #14361676


ソースコード 拡げる

from heapq import heapify, heappush, heappop
import sys
input = sys.stdin.readline

def solve():
    numY = 2*10**5
    #numY = 5

    N, Q = map(int, input().split())
    PQs = [[] for _ in range(numY)]
    bels = [-1] * N
    rates = [0] * N
    for no in range(N):
        A, B = map(int, input().split())
        B -= 1
        heappush(PQs[B], (-A, no))
        bels[no] = B
        rates[no] = A

    PQMAX = []
    for y in range(numY):
        if PQs[y]:
            m, no = PQs[y][0]
            heappush(PQMAX, (-m, y, -1))

    tmUpdates = [-1] * numY
    anss = []
    for tm in range(Q):
        C, D = map(int, input().split())
        C, D = C-1, D-1
        # 転園元
        bel = bels[C]
        rate, no = PQs[bel][0]
        if no == C:
            while 1:
                heappop(PQs[bel])
                if not PQs[bel]:
                    tmUpdates[bel] = tm
                    break
                rate, no = PQs[bel][0]
                if no != C and bels[no] == bel:
                    heappush(PQMAX, (-rate, bel, tm))
                    tmUpdates[bel] = tm
                    break

        # 転園先
        if PQs[D]:
            rate0, no = PQs[D][0]
            heappush(PQs[D], (-rates[C], C))
            rate, no = PQs[D][0]
            if rate < rate0:
                heappush(PQMAX, (-rate, D, tm))
                tmUpdates[D] = tm
        else:
            rate = rates[C]
            heappush(PQs[D], (-rate, C))
            heappush(PQMAX, (rate, D, tm))
            tmUpdates[D] = tm

        # min
        rate, y, tm = PQMAX[0]
        while tm < tmUpdates[y]:
            heappop(PQMAX)
            rate, y, tm = PQMAX[0]

        anss.append(rate)

        bels[C] = D

    print('\n'.join(map(str, anss)))


solve()

提出情報

提出日時
問題 E - Smart Infants
ユーザ ZollingerPython3
言語 Python (3.8.2)
得点 500
コード長 1849 Byte
結果 AC
実行時間 1220 ms
メモリ 135052 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果 AC
AC × 11
セット名 テストケース
Sample
All handmade02, handmade03, handmade04, handmade05, handmade06, handmade07, handmade08, handmade09, random10, sample00, sample01
ケース名 結果 実行時間 メモリ
handmade02 AC 62 ms 24644 KiB
handmade03 AC 61 ms 24528 KiB
handmade04 AC 59 ms 24776 KiB
handmade05 AC 512 ms 49792 KiB
handmade06 AC 661 ms 106580 KiB
handmade07 AC 725 ms 107296 KiB
handmade08 AC 1220 ms 135052 KiB
handmade09 AC 1213 ms 134960 KiB
random10 AC 1211 ms 134540 KiB
sample00 AC 62 ms 24640 KiB
sample01 AC 59 ms 24532 KiB