結果

問題 No.2710 How many more?
ユーザー playerplayer
提出日時 2024-04-04 15:59:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 903 bytes
コンパイル時間 414 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 107,776 KB
最終ジャッジ日時 2024-04-04 15:59:27
合計ジャッジ時間 9,480 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,596 KB
testcase_01 AC 41 ms
55,596 KB
testcase_02 AC 525 ms
105,708 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 283 ms
98,944 KB
testcase_06 WA -
testcase_07 AC 214 ms
77,476 KB
testcase_08 AC 239 ms
83,700 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 389 ms
89,488 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 40 ms
55,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *

n, q = map(int, input().split())
a = list(map(int, input().split()))

b = [None] * n
d = defaultdict(int)
pl = defaultdict(int)
for i in range(n):
    b[i] = (a[i], i)
    d[i] = a[i]
    pl[a[i]] += 1
b.sort()

# ゼッケンiが全体で前から何番目か
ans = [None] * n
flg = False
# print(pl)
for i in range(n):
    di, p = b[i]
    # print(di, p)
    if i == 0:
        ans[p] = 0
        former = p
    else:
        if d[former] == di:
            ans[p] = ans[former]
            flg = True
        else:
            if not flg:
                ans[p] = ans[former] + 1
            else:
                ans[p] = ans[former] + pl[d[former]]
                flg = False
        former = p

# print(ans)

for _ in range(q):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    if d[x] <= d[y]:
        print(0)
    else:
        print(ans[x] - ans[y]-1)
0