結果

問題 No.2710 How many more?
ユーザー FromBooska
提出日時 2024-03-31 17:59:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 476 ms / 2,000 ms
コード長 553 bytes
コンパイル時間 334 ms
コンパイル使用メモリ 82,436 KB
実行使用メモリ 92,168 KB
最終ジャッジ日時 2024-09-30 21:12:50
合計ジャッジ時間 7,024 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

# 入力例1であれば2番が1番に追いつくには7と20の間に数字が何個あるか数えればいい
# bisect_right, bisect_leftでどうか

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

from bisect import bisect_right, bisect_left

ans_list = []
for q in range(Q):
    x, y = map(int, input().split())
    x_idx = bisect_left(A_sorted, A[x-1])
    y_idx = bisect_right(A_sorted, A[y-1])
    #print('x', x, 'y', y, 'x_idx', x_idx, 'y_idx', y_idx)
    ans = max(x_idx - y_idx, 0)
    print(ans)
0