結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,596 KB
testcase_01 AC 39 ms
55,596 KB
testcase_02 AC 501 ms
105,708 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 206 ms
77,604 KB
testcase_08 AC 210 ms
83,828 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 357 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

for i in range(n):
    di, p = b[i]
    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[former]
            flg = False
        former = p

# print(ans)

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