結果

問題 No.3128 Isosceles Triangle
ユーザー nasutarou1341
提出日時 2025-04-25 22:51:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 511 ms / 2,500 ms
コード長 1,534 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 82,308 KB
実行使用メモリ 186,872 KB
最終ジャッジ日時 2025-04-25 22:52:00
合計ジャッジ時間 8,139 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

class nibutan:
  @staticmethod
  def nibutan(ok, ng, op):
    while abs(ok - ng) > 1:
      mid = (ok + ng) >> 1
      if op(mid):
        ok = mid
      else:
        ng = mid
    return ok
  @staticmethod
  def lt(L, n):
    """Lのうちn未満の最大の要素"""
    if L[0] >= n: return -1
    def op(mid):
      return L[mid] < n 
    ok = 0
    ng = len(L)
    return nibutan.nibutan(ok, ng, op)

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

N = int(input())
A = list(map(int, input().split()))

L = []
R = {}
for a in A:
  if a in R:
    R[a] += 1
  else:
    R[a] = 1
    L.append(a)

def nasu(x):
  if x == 1: return 0
  return x * (x - 1) // 2

ans = 0
n = 0
Q = {}
L.sort()
M = len(L)
S = [0] * M
S[0] = R[L[0]]
for i in range(1, M):
  S[i] += S[i - 1] + R[L[i]]

for k, v in R.items():
  Q[k] = nasu(v)
  n += Q[k]
  t = nibutan.lt(L, k * 2)
  c = S[t] - v
  ans += c * Q[k]

print(ans)
0