結果
| 問題 | No.2710 How many more? |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-03-10 00:08:03 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 237 ms / 2,000 ms |
| コード長 | 981 bytes |
| 記録 | |
| コンパイル時間 | 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 |
ソースコード
## 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()