Logo
(追記) (追記ここまで)

32591번 - Horrendous Mistake 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
8 초 (추가 시간 없음) 1024 MB87685.714%

문제

While looking through the Grand Archive of Problematic Code, you found this horrendous mistake in one of the code snippets. In this code, they tried to calculate the sum of an array, but got indices and values mixed up. The code of this sum function is shown in Figure H.1.

long long sum(vector<int> a) {
 long long ans = 0;
 for (int x : a)
 ans += a[x];
 return ans;
}
def sum(a: list[int]) -> int:
 ans = 0
 for x in a:
 ans += a[x]
 return ans
long sum(int[] a) {
 long ans = 0;
 for (int x : a)
 ans += a[x];
 return ans;
}
fun sum(a: List<Int>): Long {
 var ans = 0L
 for (x in a)
 ans += a[x]
 return ans
}

Figure H.1: The function sum intends to calculate the sum of an array, but x refers to a value in the array, instead of an index. The code is shown in C++ and Python in the top row, and Java and Kotlin in the bottom row.

You wonder how this function behaves exactly, and decide to thoroughly test it. Starting with some initial array, you apply a sequence of updates. For each update, you change one of the values of the array. You wonder what the value of the function is after each update.

입력

The input consists of:

  • One line with an integer $n$ (1ドル\leq n\leq 2\cdot10^5$), the length of the array.
  • One line with $n$ integers $a$ (0ドル \leq a < n$), the values in the initial array.
  • One line with an integer $t$ (1ドル \leq t \leq 2\cdot10^5$), the number of updates in your sequence of testing.
  • $t$ lines, each with two integers $x$ and $v$ (0ドル \leq x,v < n$), indicating that the $x$th entry in the array is updated to the new value $v$.

Note that the array uses 0ドル$-based indexing.

출력

For each update, output the return value of the function sum applied to the array after applying the update.

제한

예제 입력 1

5
0 0 3 2 0
4
1 1
0 4
3 4
1 4

예제 출력 1

6
10
9
8

예제 입력 2

5
4 2 2 4 2
3
0 1
4 3
2 3

예제 출력 2

10
13
16

힌트

출처

University > Delft University of Technology > Freshmen Programming Contest 2024 H번

  • 문제를 만든 사람: Jeroen Op de Beek
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /