結果

問題 No.2710 How many more?
ユーザー FromBooskaFromBooska
提出日時 2024-03-31 17:59:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 523 ms / 2,000 ms
コード長 553 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 91,604 KB
最終ジャッジ日時 2024-03-31 17:59:23
合計ジャッジ時間 7,618 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,332 KB
testcase_01 AC 38 ms
53,332 KB
testcase_02 AC 446 ms
84,172 KB
testcase_03 AC 302 ms
84,320 KB
testcase_04 AC 240 ms
91,136 KB
testcase_05 AC 226 ms
81,916 KB
testcase_06 AC 220 ms
87,604 KB
testcase_07 AC 263 ms
77,268 KB
testcase_08 AC 222 ms
78,256 KB
testcase_09 AC 406 ms
87,556 KB
testcase_10 AC 269 ms
81,768 KB
testcase_11 AC 385 ms
80,264 KB
testcase_12 AC 498 ms
89,500 KB
testcase_13 AC 496 ms
91,352 KB
testcase_14 AC 495 ms
91,604 KB
testcase_15 AC 507 ms
91,604 KB
testcase_16 AC 491 ms
91,604 KB
testcase_17 AC 523 ms
91,352 KB
testcase_18 AC 37 ms
53,332 KB
権限があれば一括ダウンロードができます

ソースコード

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