結果

問題 No.3085 Easy Problems
ユーザー nasutarou1341
提出日時 2025-04-05 11:56:52
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,971 bytes
コンパイル時間 343 ms
コンパイル使用メモリ 82,092 KB
実行使用メモリ 144,104 KB
最終ジャッジ日時 2025-04-05 11:57:01
合計ジャッジ時間 6,402 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other TLE * 1 -- * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

class nibutan:
  @staticmethod
  def nibutan(ok, ng, op):
    while abs(ok - ng) > 1:
      mid = (ok + ng) // 2
      if op(mid):
        ok = mid
      else:
        ng = mid
    return ok

  class nibutan_ins:
    def __init__(self, L, n):
      self.L = L
      self.n = n
    def op_lt(self, mid): return self.L[mid] < self.n
    def op_le(self, mid): return self.L[mid] <= self.n
    def op_gt(self, mid): return self.L[mid] > self.n
    def op_ge(self, mid): return self.L[mid] >= self.n

  def lt(L, n):
    """Lのうちn未満の最大の要素"""
    if len(L) == 0: return -1
    if L[0] >= n: return -1
    ok, ng = 0, len(L)
    nb = nibutan.nibutan_ins(L, n)
    return nibutan.nibutan(ok, ng, nb.op_lt)

  @staticmethod
  def le(L, n):
    """Lのうちn以下の最大の要素"""
    if len(L) == 0: return -1
    if L[0] > n: return -1
    ok, ng = 0, len(L)
    nb = nibutan.nibutan_ins(L, n)
    return nibutan.nibutan(ok, ng, nb.op_le)
      
  @staticmethod
  def gt(L, n):
    """Lのうちn超過の最小の要素"""
    if len(L) == 0: return 0
    if L[-1] <= n: return len(L)
    ok, ng = len(L) - 1, -1
    nb = nibutan.nibutan_ins(L, n)
    return nibutan.nibutan(ok, ng, nb.op_gt)
      
  @staticmethod
  def ge(L, n):
    """Lのうちn以上の最小の要素"""
    if len(L) == 0: return 0
    if L[-1] < n: return len(L)
    ok, ng = len(L) - 1, -1
    nb = nibutan.nibutan_ins(L, n)
    return nibutan.nibutan(ok, ng, nb.op_ge)

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
Q = int(input())
XY = [list(map(int, input().split())) for _ in range(Q)]

A = [AB[i][0] for i in range(N)]
A.sort()
M = 10 ** 5 + 1
AL = [None for _ in range(M)]
for a, b in AB:
  if AL[b] == None: AL[b] = []
  AL[b].append(a)
for i in range(M):
  if AL[b] != None: 
    AL[b].sort()

for x, y in XY:
  a = nibutan.le(A, x) + 1
  if AL[y] != None:
    b = nibutan.le(AL[y], x) + 1
  else:
    b = 0
  ans = a - b
  print(ans)

0