round you will begin from the furthest left square 1 and leap to the right. In case you are presently on the I-th square, you can do one of the accompanying two activities: Leap to the i+1-th square and pay the expense computer based intelligence. On the off chance that i=n, you can end the round and pay the expense computer based intelligence. Leap to the j-th square and pay the expense bi, where j is the furthest
Correct answer will be upvoted else downvoted. Computer science.
In round you will begin from the furthest left square 1 and leap to the right. In case you are presently on the I-th square, you can do one of the accompanying two activities:
Leap to the i+1-th square and pay the expense computer based intelligence. On the off chance that i=n, you can end the round and pay the expense computer based intelligence.
Leap to the j-th square and pay the expense bi, where j is the furthest left square that fulfills j>i,pj>pi. Assuming there is no such j, you can end the round and pay the expense bi.
There are q adjusts in the game. To make the game more troublesome, you wanted to keep a square set S (at first it is vacant). You should go through these squares during the round (different squares can likewise be gone through). The square set S for the I-th round is acquired by adding or eliminating a square from the square set for the (i−1)- th round.
For each round track down the base expense you should pay to end it.
Input
The principal line contains two integers n, q (1≤n,q≤2⋅105) — the number of squares and the number of rounds.
The subsequent line contains n particular integers p1,p2,… ,pn (1≤pi≤n). It is ensured that the succession p1,p2,… ,pn structures a change.
The third line contains n integers a1,a2,… ,an (−109≤
The fourth line contains n integers b1,b2,… ,bn (−109≤bi≤109).
Then, at that point, q lines follow, I-th of them contains a solitary integer xi (1≤xi≤n). In case xi was in the set S on the (i−1)- th round you should eliminate it, if not, you should add it.
Output
Print q lines, every one of them ought to contain a solitary integer — the base expense you should pay to end the comparing round.
Step by step
Solved in 4 steps with 1 images