QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 4096 MB Total points: 100 Difficulty: [show]

#13648. A + B クエリ

الإحصائيات

Quechuaの人々は、IOI 2025への歓迎の印として、長さ $N$ の2つの配列 $A$ と $B$ をあなたに贈ります。 両方の配列の要素は $0$ から $N - 1$ までインデックス付けされています。

彼らからの贈り物を大切に扱っているかを確認するため、彼らはあなたに $Q$ 個の質問を一度に1つずつ行います。 各質問は2つのインデックス $i$ と $j$ で構成され、「$A[i]$ と $B[j]$ の和はいくつか?」と尋ねられます。

実装の詳細

あなたが実装すべき最初のプロシージャは以下の通りです。

void initialize(std::vector<int> A, std::vector<int> B)
  • $A, B$: 長さ $N$ の2つの配列であり、Quechuaからの贈り物です。
  • このプロシージャは、各テストケースに対して answer_question が呼び出される前に、ちょうど1回呼び出されます。

あなたが実装すべき2番目のプロシージャは以下の通りです。

int answer_question(int i, int j)
  • $i, j$: 質問を表す整数です。
  • このプロシージャは $Q$ 回呼び出されます。

このプロシージャは $A[i]$ と $B[j]$ の和を返す必要があります。

制約

  • $1 \le N \le 200\,000$
  • $0 \le A[k], B[k] \le 10^9$ ($0 \le k < N$ を満たすすべての $k$ について)
  • $1 \le Q \le 200\,000$
  • 各質問において $0 \le i, j < N$

小課題

小課題 配点 追加の制約
1 25 配列 $A$ のすべての要素は等しく、配列 $B$ のすべての要素も等しい。
2 35 $N \le 1000$
3 40 追加の制約なし。

入出力例

以下の呼び出しを考えます。

initialize([2, 1, 3], [0, 7, 8])

この場合、$N = 3$ であり、あなたに贈られた2つの配列は $A = [2, 1, 3]$ および $B = [0, 7, 8]$ です。

次に、以下の呼び出しを考えます。

answer_question(0, 1)

この呼び出しは $A[0] = 2$ と $B[1] = 7$ の和である $9$ を返す必要があります。

以下の呼び出しを考えます。

answer_question(2, 2)

この呼び出しは $A[2] + B[2] = 3 + 8 = 11$ を返す必要があります。

サンプルグレーダー

入力形式:

N
A[0] A[1] ... A[N-1]
B[0] B[1] ... B[N-1]
Q
i[0] j[0]
i[1] j[1]
...
i[Q-1] j[Q-1]

ここで、$i[k]$ および $j[k]$ ($0 \le k < Q$) は、各 answer_question 呼び出しのパラメータを指定します。

出力形式:

S[0]
S[1]
...
S[Q-1]

ここで、$S[k]$ ($0 \le k < Q$) は answer_question(i[k], j[k]) の呼び出しによって返される整数です。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.