結果

問題 No.2710 How many more?
コンテスト
ユーザー LyricalMaestro
提出日時 2026-03-10 00:08:03
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 237 ms / 2,000 ms
コード長 981 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 276 ms
コンパイル使用メモリ 85,112 KB
実行使用メモリ 123,852 KB
最終ジャッジ日時 2026-03-10 00:08:08
合計ジャッジ時間 4,788 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

## https://yukicoder.me/problems/no/2710


def main():
    N, Q = map(int, input().split())
    A = list(map(int, input().split()))
    xy = []
    for _ in range(Q):
        x, y = map(int, input().split())
        xy.append((x - 1, y- 1))

    
    a_map = {}
    for i in range(N):
        a = A[i]
        if a not in a_map:
            a_map[a] = 0
        a_map[a] += 1
    
    array = [(a, cnt) for a, cnt in a_map.items()]
    array.sort(key=lambda x: x[0])

    a_index = {}
    for i, a_tuple in enumerate(array):
        a_index[a_tuple[0]] = i

    cum_array = [0] * len(array)
    c = 0
    for i in range(len(array)):    
        c += array[i][1]
        cum_array[i] = c
    
    for x, y in xy:
        a_x = A[x]
        a_y = A[y]
        if a_y < a_x:
            ind_y = a_index[a_y]
            ind_x = a_index[a_x]
            print(cum_array[ind_x - 1] - cum_array[ind_y] )
        else:
            print(0)
    






if __name__ == "__main__":
    main()
0