結果

問題 No.759 悪くない忘年会にしような!
ユーザー tktk_snsntktk_snsn
提出日時 2022-05-12 13:08:56
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 1,721 bytes
コンパイル時間 529 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 130,204 KB
最終ジャッジ日時 2023-09-27 12:19:46
合計ジャッジ時間 20,564 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,884 KB
testcase_01 AC 75 ms
71,792 KB
testcase_02 AC 79 ms
71,600 KB
testcase_03 AC 82 ms
71,780 KB
testcase_04 AC 75 ms
71,840 KB
testcase_05 AC 76 ms
71,728 KB
testcase_06 AC 75 ms
71,800 KB
testcase_07 AC 73 ms
71,856 KB
testcase_08 AC 76 ms
71,740 KB
testcase_09 AC 77 ms
71,604 KB
testcase_10 AC 76 ms
71,920 KB
testcase_11 AC 77 ms
71,448 KB
testcase_12 AC 75 ms
71,796 KB
testcase_13 AC 76 ms
71,596 KB
testcase_14 AC 78 ms
71,636 KB
testcase_15 AC 76 ms
71,912 KB
testcase_16 AC 78 ms
71,860 KB
testcase_17 AC 76 ms
71,740 KB
testcase_18 AC 74 ms
71,804 KB
testcase_19 AC 77 ms
71,732 KB
testcase_20 AC 77 ms
71,524 KB
testcase_21 AC 75 ms
71,756 KB
testcase_22 AC 77 ms
71,636 KB
testcase_23 AC 75 ms
71,792 KB
testcase_24 AC 76 ms
71,636 KB
testcase_25 AC 75 ms
71,660 KB
testcase_26 AC 75 ms
71,864 KB
testcase_27 AC 76 ms
71,608 KB
testcase_28 AC 73 ms
71,804 KB
testcase_29 WA -
testcase_30 AC 76 ms
71,800 KB
testcase_31 AC 76 ms
71,596 KB
testcase_32 AC 76 ms
71,740 KB
testcase_33 AC 255 ms
84,500 KB
testcase_34 AC 127 ms
79,412 KB
testcase_35 AC 220 ms
82,416 KB
testcase_36 AC 243 ms
83,252 KB
testcase_37 AC 146 ms
79,912 KB
testcase_38 AC 261 ms
83,924 KB
testcase_39 AC 148 ms
79,620 KB
testcase_40 AC 255 ms
82,392 KB
testcase_41 AC 262 ms
84,276 KB
testcase_42 AC 267 ms
84,168 KB
testcase_43 AC 278 ms
84,140 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 289 ms
85,028 KB
testcase_50 AC 276 ms
84,924 KB
testcase_51 AC 264 ms
84,296 KB
testcase_52 AC 268 ms
84,512 KB
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 AC 610 ms
130,056 KB
testcase_64 WA -
testcase_65 AC 710 ms
117,248 KB
testcase_66 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import heapq
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 in enumerate(P):
    d[ptoi[p]].append(i)

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


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

    stf = []
    stg = []
    while F and G:
        if Q[F[-1]] <= Q[G[-1]]:
            heapq.heappush(stf, (R[F[-1]], F[-1]))
            F.pop()
        else:
            while stf and stf[0][0] <= R[G[-1]]:
                heapq.heappop(stf)
            stg.append(G.pop())
    while F:
        heapq.heappush(stf, (R[F[-1]], F[-1]))
        F.pop()
    while G:
        while stf and stf[0][0] <= R[G[-1]]:
            heapq.heappop(stf)
        stg.append(G.pop())

    stf = [k for _, k in stf]
    stf.sort(key=lambda k: Q[k], reverse=True)
    stg.reverse()
    while stf and stg:
        if Q[stf[-1]] <= Q[stg[-1]]:
            d[i].append(stf.pop())
        else:
            d[i].append(stg.pop())
    while stf:
        d[i].append(stf.pop())
    while stg:
        d[i].append(stg.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 = [i + 1 for i in d[0]]
ans.sort()
print(*ans, sep="\n")
0