Last active
September 4, 2021 16:36
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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