結果

問題 No.759 悪くない忘年会にしような!
ユーザー tktk_snsn
提出日時 2022-05-12 12:46:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,586 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 150,912 KB
最終ジャッジ日時 2024-07-20 05:57:24
合計ジャッジ時間 14,449 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30 WA * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


N = int(input())
PQR = tuple(tuple(map(int, input().split())) for _ in range(N))
P, Q, R = zip(*PQR)

ptoi = {p: i for i, p in enumerate(sorted(set(P)))}
M = len(ptoi)
d = [[] for _ in range(M)]
for i, (p, q, r) in enumerate(PQR, 1):
    d[ptoi[p]].append((q, r, i))

for i in range(M):
    stack = []
    d[i].sort()
    for q, r, j in d[i]:
        if stack and stack[-1][1] <= r:
            stack.pop()
        stack.append((q, r, j))
    d[i] = stack
    d[i].reverse()


def merge(i, j):
    F = d[i]
    G = d[j]
    st0 = []
    st1 = []

    while F and G:
        if F[-1][0] <= G[-1][0]:
            st0.append(F.pop())
        else:
            while st0 and st0[-1][1] <= G[-1][1]:
                st0.pop()
            st1.append(G.pop())
    while F:
        st0.append(F.pop())
    while G:
        while st0 and st0[-1][1] <= G[-1][1]:
            st0.pop()
        st1.append(G.pop())

    st0.reverse()
    st1.reverse()
    while st0 and st1:
        if st0[-1][0] <= st1[-1][0]:
            d[i].append(st0.pop())
        else:
            d[i].append(st1.pop())
    while st0:
        d[i].append(st0.pop())
    while st1:
        d[i].append(st1.pop())
    d[i].reverse()


que = deque(range(M))
while len(que) > 1:
    a = que.popleft()
    b = que.popleft()
    if a > b:
        que.append(a)
        que.appendleft(b)
        continue
    merge(a, b)
    que.append(a)


ans = []
for _, _, i in d[0]:
    ans.append(i)
ans.sort()
print(*ans, sep="\n")
0