fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
백준 34210 (C++) A + B Queries
최초 업로드: 2025-08-24 13:39:11
최근 수정 시간: 2025-08-24 13:39:44
게시자: rlatjwls3333
카테고리: 백준
조회수: 32
# [Bronze V] A + B Queries [문제 링크](https://www.acmicpc.net/problem/34210) ## 문제 설명 <p>The Quechuas welcome you to IOI 2025 with a special gift: two arrays, $A$ and $B$, each of length $N$. The elements in both arrays are indexed from $0$ to $N − 1$.</p> <p>To ensure that you are taking good care of their gift, they will ask you $Q$ questions, one at a time. Each question consists of two indices, $i$ and $j$, and asks: What is the sum of $A[i]$ and $B[j]$?</p> ## 구현 상세 <p>The first procedure you should implement is:</p> <pre> void initialize(std::vector<int> A, std::vector<int> B)</pre> <ul> <li>$A$, $B$: two arrays of length $N$, the gift of the Quechuas.</li> <li>This procedure is called exactly once for each testcase, before any calls to <code>answer_question</code>.</li> </ul> <p>The second procedure you should implement is:</p> <pre> int answer_question(int i, int j)</pre> <ul> <li>$i$, $j$: integers describing a question.</li> <li>This procedure is called $Q$ times.</li> </ul> <p>This procedure should return the sum of $A[i]$ and $B[j]$.</p> ## 제한 <ul> <li>$1 ≤ N ≤ 200\, 000$</li> <li>$0 ≤ A[k],B[k] ≤ 10$ for each $k$ such that $0 ≤ k < N$.</li> <li>$1 ≤ Q ≤ 200\, 000$</li> <li>$0 ≤ i, j < N$ in each question.</li> </ul> ## 풀이 #### initialize에서 A, B 배열을 저장하고, answer_question에서 A[i]+B[j]를 출력하면 된다. ``` c++ #include<bits/stdc++.h> #include "aplusb.h" using namespace std; vector<int> a, b; void initialize(vector<int> A, vector<int> B) { a = A; b = B; return; } int answer_question(int i, int j) { return a[i] + b[j]; } ```