ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 16221 |
문제명 | 모독 |
레벨 | 플래티넘 3 |
분류 |
구간 쿼리 |
시간복잡도 | O(n+qlogn) |
인풋사이즈 | n<=1,000,000, q<=1,000,000 |
사용한 언어 | PyPy |
제출기록 | 223956KB / 2796ms |
최고기록 | 2796ms |
해결날짜 | 2021/04/13 |
"""Solution code for "BOJ 16221. 모독".
- Problem link: https://www.acmicpc.net/problem/16221
- Solution link: http://www.teferi.net/ps/problems/boj/16221
"""
import heapq
import sys
from teflib import fenwicktree
MAX_K = 1_000_000
def main():
Q = int(sys.stdin.readline())
fenwick = fenwicktree.FenwickTree(MAX_K + 2)
zeros = list(range(1, MAX_K + 2))
heapq.heapify(zeros)
for _ in range(Q):
T, K = [int(x) for x in sys.stdin.readline().split()]
if T == 1:
fenwick.update(K, 1)
if fenwick.get(K) == 1 and K == zeros[0]:
while fenwick.get(zeros[0]) > 0:
heapq.heappop(zeros)
else:
fenwick.update(K, -1)
if fenwick.get(K) == 0:
heapq.heappush(zeros, K)
print(fenwick.query(1, zeros[0]))
if __name__ == '__main__':
main()