結果

問題 No.2710 How many more?
ユーザー miya145592miya145592
提出日時 2024-03-31 14:48:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 281 ms / 2,000 ms
コード長 509 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 127,392 KB
最終ジャッジ日時 2024-03-31 14:48:31
合計ジャッジ時間 4,727 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,612 KB
testcase_01 AC 44 ms
55,608 KB
testcase_02 AC 209 ms
103,984 KB
testcase_03 AC 168 ms
98,320 KB
testcase_04 AC 187 ms
115,516 KB
testcase_05 AC 136 ms
92,216 KB
testcase_06 AC 163 ms
99,984 KB
testcase_07 AC 111 ms
81,964 KB
testcase_08 AC 114 ms
84,620 KB
testcase_09 AC 211 ms
115,492 KB
testcase_10 AC 148 ms
95,800 KB
testcase_11 AC 167 ms
95,636 KB
testcase_12 AC 276 ms
122,340 KB
testcase_13 AC 269 ms
127,392 KB
testcase_14 AC 260 ms
127,388 KB
testcase_15 AC 258 ms
127,264 KB
testcase_16 AC 281 ms
127,392 KB
testcase_17 AC 269 ms
127,256 KB
testcase_18 AC 41 ms
55,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
A = list(map(int, input().split()))
XY = [list(map(int, input().split())) for _ in range(Q)]
B = defaultdict(int)
for i, a in enumerate(A):
    B[a] += 1
P = list(B.keys())
P.sort(reverse=True)
Z = dict()
S = [0]
for i in range(len(P)):
    p = P[i]
    Z[p] = i
    S.append(S[-1]+B[p])
for x, y in XY:
    x-=1
    y-=1
    xi = Z[A[x]]
    yi = Z[A[y]]
    ans = max(0, S[yi]-S[xi+1])
    print(ans)
0