結果

問題 No.618 labo-index
ユーザー lam6er
提出日時 2025-04-16 16:08:18
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,502 bytes
コンパイル時間 511 ms
コンパイル使用メモリ 81,640 KB
実行使用メモリ 152,464 KB
最終ジャッジ日時 2025-04-16 16:15:46
合計ジャッジ時間 5,677 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 4 RE * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    idx = 0
    Q = int(data[idx])
    idx += 1
    
    active = []
    sorted_values = []
    delta = 0
    
    for _ in range(Q):
        t = int(data[idx])
        x = int(data[idx + 1])
        idx += 2
        
        if t == 1:
            stored = x - delta
            active.append(stored)
            bisect.insort(sorted_values, stored)
        elif t == 2:
            x -= 1  # convert to 0-based
            stored = active[x]
            pos = bisect.bisect_left(sorted_values, stored)
            while pos < len(sorted_values) and sorted_values[pos] == stored:
                if (x == 0 or (active[:x].count(stored) == active[:x+1].count(stored) - 1)):
                    sorted_values.pop(pos)
                    break
                pos += 1
            active.pop(x)
        elif t == 3:
            delta += x
        
        N = len(sorted_values)
        if N == 0:
            print(0)
            continue
        
        low = 1
        high = N
        best = 0
        while low <= high:
            mid = (low + high) // 2
            if mid > N:
                high = mid - 1
                continue
            idx_mid = N - mid
            if idx_mid >= 0 and sorted_values[idx_mid] + delta >= mid:
                best = mid
                low = mid + 1
            else:
                high = mid - 1
        print(best)

if __name__ == "__main__":
    main()
0