QOJ.ac

QOJ

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

#13648. A + B 查询

統計

Quechua 人民以一份特别的礼物欢迎你参加 IOI 2025:两个长度均为 $N$ 的数组 $A$ 和 $B$。两个数组中的元素下标均从 $0$ 到 $N - 1$。

为了确保你妥善保管了这份礼物,他们会依次向你提出 $Q$ 个问题。每个问题包含两个下标 $i$ 和 $j$,询问:$A[i]$ 与 $B[j]$ 的和是多少?

实现细节

你需要实现以下第一个过程:

void initialize(std::vector<int> A, std::vector<int> B)
  • $A, B$:长度为 $N$ 的两个数组,即 Quechua 人民的礼物。
  • 对于每个测试用例,该过程在任何 answer_question 调用之前恰好被调用一次。

你需要实现以下第二个过程:

int answer_question(int i, int j)
  • $i, j$:描述问题的整数。
  • 该过程会被调用 $Q$ 次。
  • 该过程应返回 $A[i]$ 与 $B[j]$ 的和。

数据范围

  • $1 \le N \le 200\,000$
  • 对于满足 $0 \le k < N$ 的每个 $k$,有 $0 \le A[k], B[k] \le 10^9$
  • $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$,赠予你的两个数组为 $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.