Skip to content

Instantly share code, notes, and snippets.

@maehrm
Created March 15, 2026 00:32
Show Gist options
  • Select an option

  • Save maehrm/77f7b5fd16c214cad847385096d3990e to your computer and use it in GitHub Desktop.

Select an option

Save maehrm/77f7b5fd16c214cad847385096d3990e to your computer and use it in GitHub Desktop.
N, D, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(D)]
ST = [list(map(int, input().split())) for _ in range(K)]
ans = [-1] * K
for i in range(D): # i日目
l, r = LR[i]
for j in range(K): # j番目の民族の移動
if ans[j] != -1:
continue
cur, goal = ST[j]
if cur < goal and cur >= l and cur <= r: # 現在地がゴールの左側のとき
cur = min(r, goal)
if goal < cur and cur <= r and cur >= l: # 現在地がゴールの右側のとき
cur = max(l, goal)
ST[j][0] = cur
if cur == goal:
ans[j] = str(i + 1)
print("\n".join(ans))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment