結果

問題 No.568 じゃんじゃん 落とす 委員会
ユーザー mkawa2
提出日時 2020-05-23 10:47:51
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,671 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 46,768 KB
最終ジャッジ日時 2024-10-07 14:36:29
合計ジャッジ時間 9,395 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from operator import itemgetter
import sys
from heapq import *

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    inf=10**9
    n,m=MI()
    abx=defaultdict(list)
    bax=defaultdict(list)
    cnt2=cnt3=0
    bb=set()
    for _ in range(n):
        x,a,b=MI()
        if x>=3:cnt3+=1
        else:
            abx[a].append((b,x))
            bax[b].append((a,x))
            bb.add(b)
        if x==2:cnt3+=1
        if x==1:cnt2+=1
    bb=list(sorted(bb))

    hp0=[]
    hp12=[]
    hp10=[]
    hp2=[]
    ans=cnt3
    sb=inf
    for a,bx in sorted(abx.items()):
        sa=a
        for b,x in bx:
            if x==2 and b<sb:heappush(hp2,-b);cnt2+=1;cnt3-=1
            if x==1 and b<sb:heappush(hp10,-b);cnt2-=1
        while hp0 and hp0[0]<=sa:heappop(hp0);cnt2-=1
        while hp12 and hp12[0]<=sa:heappop(hp12);cnt3-=1;cnt2+=1

        while bb and cnt2+cnt3<m:
            sb=bb.pop()
            for a,x in bax[sb]:
                if x==0 and a>sa:heappush(hp0,a);cnt2+=1
                if x==1 and a>sa:heappush(hp12,a);cnt2-=1;cnt3+=1
            while hp2 and -hp2[0]>=sb:heappop(hp2);cnt3+=1;cnt2-=1
            while hp10 and -hp10[0]>=sb:heappop(hp10);cnt2+=1
        #print(cnt2,cnt3,hp0,hp10,hp12,hp2)
        if cnt2+cnt3<m:break

        ans=min(ans,cnt3)

    print(ans)

main()
0