結果

問題 No.2710 How many more?
ユーザー 👑 KA37RIKA37RI
提出日時 2024-03-31 14:58:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 567 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 98,504 KB
最終ジャッジ日時 2024-03-31 14:58:39
合計ジャッジ時間 5,269 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 40 ms
53,460 KB
testcase_02 AC 247 ms
91,120 KB
testcase_03 AC 204 ms
86,172 KB
testcase_04 AC 229 ms
89,968 KB
testcase_05 AC 160 ms
83,316 KB
testcase_06 AC 200 ms
87,476 KB
testcase_07 AC 135 ms
80,768 KB
testcase_08 AC 137 ms
80,468 KB
testcase_09 AC 244 ms
91,920 KB
testcase_10 AC 171 ms
84,360 KB
testcase_11 AC 195 ms
86,016 KB
testcase_12 AC 288 ms
97,276 KB
testcase_13 AC 314 ms
98,504 KB
testcase_14 AC 309 ms
98,500 KB
testcase_15 AC 312 ms
98,500 KB
testcase_16 AC 313 ms
98,500 KB
testcase_17 AC 309 ms
98,504 KB
testcase_18 AC 35 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(n, q, a, xy):
  b = sorted(range(n), key=lambda x: a[x])
  c = [0] * n
  d = [0] * n
  for i, x in enumerate(b):
    if i > 0 and a[b[i-1]] == a[x]:
      c[x] = c[b[i-1]]
    else:
      c[x] = i
  for i, x in reversed(list(enumerate(b))):
    if i < n - 1 and a[b[i+1]] == a[x]:
      d[x] = d[b[i+1]]
    else:
      d[x] = i
  # print(c)
  for x, y in xy:
    print(max(c[x] - d[y] - 1, 0))

n, q = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
xy = [[int(x) - 1 for x in input().split()] for _ in range(q)]

solve(n, q, a, xy)
0