公式

A - テストの点数比較 / Comparing Test Scores 解説 by admin

Qwen3-Coder-480B

Overview

In this problem, you are given the test scores of multiple students, and for each query specifying two students, you must determine whether one student’s score is strictly higher than the other’s.

Analysis

This problem only requires simple comparisons, but there are several important points to note:

  • All student scores are given upfront, so for each query you simply look up the scores. This means it can be processed efficiently even without any preprocessing.
  • Student ID numbers are 1-indexed, but array indices in languages like Python are 0-indexed, so you need to subtract 1 when accessing elements.
  • “Strictly higher” means that equal scores are not included. For example, if the scores are the same, you should output No.
  • There can be up to \(10^5\) queries, so it is important that each query can be processed in constant time.

Since the score comparison itself is straightforward, no precomputation is needed, and each query can be answered immediately, no special algorithms or data structures are required.

Algorithm

  1. First, read the number of students \(N\) and the number of queries \(Q\).
  2. Store each student’s score \(S_1, S_2, ..., S_N\) in a list or similar data structure.
  3. For each query, student ID numbers \(a_i\) and \(b_i\) are given, so compare the corresponding scores \(S_{a_i}\) and \(S_{b_i}\).
  4. If \(S_{a_i} > S_{b_i}\), output Yes; otherwise, output No.

Complexity

  • Time complexity: \(O(N + Q)\)
    (\(O(N)\) for reading the scores, \(O(Q)\) for answering the queries)
  • Space complexity: \(O(N)\)
    (a list of size \(N\) is used to store the scores)

Implementation Notes

  • Since student ID numbers are 1-indexed, you need to subtract -1 when accessing list indices.

  • Be careful that the inequality means “strictly greater than,” i.e., >.

  • Pay attention to the input/output format and parse it correctly.

    Source Code

# 入力の読み込み
N, Q = map(int, input().split())
H = list(map(int, input().split()))

# 各質問に対する処理
for _ in range(Q):
    a, b = map(int, input().split())
    # 出席番号は1始まりなので、リストのインデックスは-1する
    if H[a - 1] > H[b - 1]:
        print("Yes")
    else:
        print("No")

This editorial was generated by qwen3-coder-480b.

投稿日時:
最終更新: