Skip to content

Instantly share code, notes, and snippets.

@uchidama
Last active September 4, 2021 16:36
Show Gist options
  • Save uchidama/39813c88939eedb07b9177ba9d30c5dd to your computer and use it in GitHub Desktop.
Save uchidama/39813c88939eedb07b9177ba9d30c5dd to your computer and use it in GitHub Desktop.
AtCoder Beginner Contest 217 [ D - Cutting Woods ] https://atcoder.jp/contests/abc217/tasks/abc217_d
import sys
import bisect
import array
input = sys.stdin.readline
L, Q = map(int, input().split())
# arrayのほうが、listより追加処理が速いようだ。約1/3軽量
A = array.array('I', [0, L])
for i in range(Q):
c, x = map(int, input().split())
if c == 1:
# 二分探索して追加
bisect.insort_left(A, x)
else:
# 二分探索
i = bisect.bisect_right(A, x)
print(A[i] - A[i-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment