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

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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≤ai≤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.

 

 

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY