/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 266 点
問題文
高橋君は N 日間の家計簿をつけています。
高橋君の口座残高は最初 0 円です。 i 日目 (1 \leq i \leq N) には A_i 円の取引が記録されており、正の値なら入金、負の値なら出金を表します。各日の取引は順に口座残高に反映されます(口座残高が途中で負になることもあり得ます)。すべての取引を反映した N 日目終了時点の口座残高は A_1 + A_2 + \cdots + A_N 円です。
しかし、高橋君は家計簿を見直しているうちに、いくつかの取引が誤って記録されていたことに気づきました。そこで彼は Q 回の修正操作を順番に行います。 j 回目 (1 \leq j \leq Q) の操作では、 D_j 日目の取引額を 0 円に変更します。一度 0 円に変更された日の取引額は、それ以降の操作においても 0 のまま変わりません。つまり、操作を重ねるごとに取引額が 0 に変更された日が増えていきます。
各操作の後、すべての日の取引額の総和、すなわち N 日目終了時点での口座残高を求めてください。
なお、 D_1, D_2, \ldots, D_Q はすべて異なります。すなわち、同じ日の取引額が複数回変更されることはありません。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq N
- -10^9 \leq A_i \leq 10^9
- 1 \leq D_j \leq N
- D_1, D_2, \ldots, D_Q はすべて異なる
- 入力はすべて整数
入力
N Q A_1 A_2 \cdots A_N D_1 D_2 \vdots D_Q
- 1 行目には、家計簿の日数を表す整数 N と、修正操作の回数を表す整数 Q が、スペース区切りで与えられる。
- 2 行目には、各日の取引額を表す N 個の整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。 A_i は i 日目の取引額である。
- 続く Q 行のうち j 行目(全体では 2 + j 行目)には、 j 回目の操作で取引額を 0 に変更する日を表す整数 D_j が1つ与えられる。
出力
Q 行出力してください。 j 行目には、 1 回目から j 回目までの操作をすべて行った後の、すべての日の取引額の総和(N 日目終了時点での口座残高)を出力してください。
入力例 1
5 3 100 -50 200 -30 80 2 4 1
出力例 1
350 380 280
入力例 2
7 4 1000 -500 300 -200 400 -100 200 3 1 5 7
出力例 2
800 -200 -600 -800
入力例 3
10 5 1000000000 -999999999 500000000 -400000000 300000000 -200000000 100000000 -50000000 25000000 -12500000 1 3 5 7 9
出力例 3
-737499999 -1237499999 -1537499999 -1637499999 -1662499999
Score : 266 pts
Problem Statement
Takahashi is keeping a household account book for N days.
Takahashi's account balance is initially 0 yen. On day i (1 \leq i \leq N), a transaction of A_i yen is recorded, where a positive value represents a deposit and a negative value represents a withdrawal. Each day's transaction is applied to the account balance in order (the account balance may become negative during the process). The account balance at the end of day N, after all transactions have been applied, is A_1 + A_2 + \cdots + A_N yen.
However, while reviewing the account book, Takahashi noticed that some transactions were recorded incorrectly. He then performs Q correction operations in order. In the j-th operation (1 \leq j \leq Q), he changes the transaction amount on day D_j to 0 yen. Once a day's transaction amount has been changed to 0, it remains 0 in all subsequent operations. In other words, with each operation, the number of days whose transaction amounts have been set to 0 increases.
After each operation, find the sum of all days' transaction amounts, that is, the account balance at the end of day N.
Note that D_1, D_2, \ldots, D_Q are all distinct. In other words, the same day's transaction amount is never changed more than once.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq N
- -10^9 \leq A_i \leq 10^9
- 1 \leq D_j \leq N
- D_1, D_2, \ldots, D_Q are all distinct
- All input values are integers
Input
N Q A_1 A_2 \cdots A_N D_1 D_2 \vdots D_Q
- The first line contains an integer N representing the number of days in the account book and an integer Q representing the number of correction operations, separated by a space.
- The second line contains N integers A_1, A_2, \ldots, A_N representing the transaction amounts for each day, separated by spaces. A_i is the transaction amount on day i.
- Among the following Q lines, the j-th line (the (2 + j)-th line overall) contains a single integer D_j representing the day whose transaction amount is changed to 0 in the j-th operation.
Output
Print Q lines. On the j-th line, print the sum of all days' transaction amounts (the account balance at the end of day N) after performing all operations from the 1-st through the j-th.
Sample Input 1
5 3 100 -50 200 -30 80 2 4 1
Sample Output 1
350 380 280
Sample Input 2
7 4 1000 -500 300 -200 400 -100 200 3 1 5 7
Sample Output 2
800 -200 -600 -800
Sample Input 3
10 5 1000000000 -999999999 500000000 -400000000 300000000 -200000000 100000000 -50000000 25000000 -12500000 1 3 5 7 9
Sample Output 3
-737499999 -1237499999 -1537499999 -1637499999 -1662499999