結果

問題 No.2710 How many more?
ユーザー playerplayer
提出日時 2024-04-04 16:21:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 675 ms / 2,000 ms
コード長 914 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 107,756 KB
最終ジャッジ日時 2024-04-04 16:22:03
合計ジャッジ時間 9,609 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,596 KB
testcase_01 AC 39 ms
55,596 KB
testcase_02 AC 499 ms
105,708 KB
testcase_03 AC 419 ms
106,108 KB
testcase_04 AC 450 ms
105,180 KB
testcase_05 AC 276 ms
98,816 KB
testcase_06 AC 363 ms
106,460 KB
testcase_07 AC 201 ms
77,604 KB
testcase_08 AC 232 ms
83,828 KB
testcase_09 AC 487 ms
106,544 KB
testcase_10 AC 303 ms
94,164 KB
testcase_11 AC 392 ms
89,488 KB
testcase_12 AC 599 ms
101,000 KB
testcase_13 AC 675 ms
107,756 KB
testcase_14 AC 636 ms
107,756 KB
testcase_15 AC 660 ms
107,756 KB
testcase_16 AC 649 ms
107,756 KB
testcase_17 AC 661 ms
107,752 KB
testcase_18 AC 38 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] - pl[d[y]])
0