結果

問題 No.2710 How many more?
ユーザー budoubudou
提出日時 2024-04-07 07:05:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 475 ms / 2,000 ms
コード長 785 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 107,056 KB
最終ジャッジ日時 2024-04-07 07:05:10
合計ジャッジ時間 8,264 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
68,232 KB
testcase_01 AC 60 ms
68,232 KB
testcase_02 AC 316 ms
91,776 KB
testcase_03 AC 294 ms
95,340 KB
testcase_04 AC 367 ms
106,012 KB
testcase_05 AC 232 ms
88,548 KB
testcase_06 AC 324 ms
99,504 KB
testcase_07 AC 131 ms
78,916 KB
testcase_08 AC 171 ms
82,028 KB
testcase_09 AC 355 ms
99,516 KB
testcase_10 AC 227 ms
86,944 KB
testcase_11 AC 221 ms
84,964 KB
testcase_12 AC 439 ms
103,464 KB
testcase_13 AC 443 ms
106,528 KB
testcase_14 AC 449 ms
106,544 KB
testcase_15 AC 475 ms
107,056 KB
testcase_16 AC 442 ms
107,052 KB
testcase_17 AC 443 ms
106,536 KB
testcase_18 AC 62 ms
68,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import typing
import sys
# sys.setrecursionlimit(100100)
from collections import defaultdict
input = lambda: sys.stdin.readline().strip()
inf = 10**18
mod = 998244353
# import heapq

def solve():
  N, Q = map(int, input().split())
  order = [-1 for _ in range(N)]
  same_order = [-1 for _ in range(N)]
  A_ = list(map(int, input().split()))
  A = [(A_[i], i) for i in range(N)]
  A.sort()
  for idx, (v, i) in enumerate(A):
    order[i] = idx
  sz = defaultdict(int)
  for i, x in enumerate(A_):
    same_order[i] = sz[x]
    sz[x] += 1
  for _ in range(Q):
    x, y = map(lambda x: int(x)-1, input().split())
    ans = order[x]-order[y]-1
    ans -= same_order[x]
    ans -= sz[A_[y]]-same_order[y]-1
    print(max(0, ans))
def main():
  t = 1
  for _ in range(t):
    solve()
main()
0