He has n watermelons and each one has a specific index denote as a. The watermelons...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
He has n watermelons and each one has a specific index denote as a₁. The watermelons are store in a cylindrical() box. Osas wants to eat a watermelon indexed a;. But if the watermelon indexed a; is not on the top, he needs to eat all watermelon above the watermelon indexed a;. For example if the index of watermelon from top to bottom is: 5, 3, 2, 1, 4. And Osas wants to eat watermelon which index is 2, then he need to eat watermelons which index are 5, 3, 2 at the same time. Osas has a list which is the order of index of watermelons he wants to eat which denoted as b₁. The length of the list is also n and all b; are distinct. Please help him calculate that each time he wants to eat a watermelon, how many watermelons he needs to eat at same time? For example if the index of watermelon from top to bottom is: 5, 3, 2, 1, 4. And the list Osas has is: 2, 3, 4, 5, 1. First time Osas will eat 3 watermelons(5,3,2). Second time because the watermelons that indexed 3 is already been eaten, Osas eat 0 watermelon. So on and so forth. In this example, you need to output: 3 0 2 0 0. Input input contains three lines. First line contains n the number of watermelons.( 1 <= n <= 2*105 ) Second line contains n integer a₁ ~ an which denote as the index of watermelons from top to bottom .( 1 <= a₁ <= n ) Third line contains n integer b₁ bn which denote as the order of the index that Osas' wants to eat.( 1 <= <= b₁ <= n ) Output output contains one line. output n integer means the number of watermelons that each time Osas eat. Separate each number by a blank but don't print the blank after the last number. remember to print \n at the end of output. Sample Input Download 5 53214 23451 Sample Output Download 30200 He has n watermelons and each one has a specific index denote as a₁. The watermelons are store in a cylindrical() box. Osas wants to eat a watermelon indexed a;. But if the watermelon indexed a; is not on the top, he needs to eat all watermelon above the watermelon indexed a;. For example if the index of watermelon from top to bottom is: 5, 3, 2, 1, 4. And Osas wants to eat watermelon which index is 2, then he need to eat watermelons which index are 5, 3, 2 at the same time. Osas has a list which is the order of index of watermelons he wants to eat which denoted as b₁. The length of the list is also n and all b; are distinct. Please help him calculate that each time he wants to eat a watermelon, how many watermelons he needs to eat at same time? For example if the index of watermelon from top to bottom is: 5, 3, 2, 1, 4. And the list Osas has is: 2, 3, 4, 5, 1. First time Osas will eat 3 watermelons(5,3,2). Second time because the watermelons that indexed 3 is already been eaten, Osas eat 0 watermelon. So on and so forth. In this example, you need to output: 3 0 2 0 0. Input input contains three lines. First line contains n the number of watermelons.( 1 <= n <= 2*105 ) Second line contains n integer a₁ ~ an which denote as the index of watermelons from top to bottom .( 1 <= a₁ <= n ) Third line contains n integer b₁ bn which denote as the order of the index that Osas' wants to eat.( 1 <= <= b₁ <= n ) Output output contains one line. output n integer means the number of watermelons that each time Osas eat. Separate each number by a blank but don't print the blank after the last number. remember to print \n at the end of output. Sample Input Download 5 53214 23451 Sample Output Download 30200
Expert Answer:
Answer rating: 100% (QA)
Time Compexity ON Space Complexity ON include include int main int n scanfd n int inputListn int ind... View the full answer
Related Book For
Probability and Statistical Inference
ISBN: 978-0321923271
9th edition
Authors: Robert V. Hogg, Elliot Tanis, Dale Zimmerman
Posted Date:
Students also viewed these programming questions
-
A grocery store has n watermelons to sell and makes $1.00 on each sale. Say the number of consumers of these watermelons is a random variable with a distribution that can be approximated by A pdf of...
-
N balls labeled 1 through N are placed in Box 1 while a Box 2 is initially empty. At each time instant, one of the N balls is chosen (with equally probability) and moved to the other box. Let X [k]...
-
If A and B are n à n matrices, then (A - B)2 = A2 - 2AB + B2. In this case answer true if the statement is always true and false otherwise. In the case of a true statement, explain or prove...
-
The homogeneous rectangular block having dimensions a-1.93, b=2.75 as shown, and mass m, rests on the inclined plane which is hinged about a horizontal axis through O. Calculate the minimum value of...
-
A ball is shot vertically upward from the surface of another planet. A plot of y versus t for the ball is shown in Figure, where y is the height of the ball above its starting point and t = 0 at the...
-
In what ways has GM's governing board shown that it embraces and supports diversity?
-
Robin Alper, a manager of the credit collections department for ACME Building Supplies, is extremely unhappy with a new system that was installed three months ago. Her complaint is that the dataflows...
-
You have been shopping for a new home. You have a choice of financing. You can choose either a $200,000 mortgage at 4.75 percent for 30 years, or a $200,000 mortgage at 3.5 percent for 15 years. a....
-
The mean exam score for 49 male high school students is 22.1 and the standard deviation is 4.5. The mean exam score for 56 female high school students is 20.6 and the standard deviation is 4.1. At a...
-
Prove that each of the following formulas for (v. tv) defines an inner product on R3. Verify all the inner product axioms in careful detail: (a) V1W1 + 2V2w2 + 3v3w3 (b) 4v1w1 + 2 v1w2 + 2v2wi +4v2W2...
-
Explain Attributes and Reflection.
-
Sample results support the conclusion that a recorded account balance is materially misstated but, unknown to the auditor, the account is not misstated, suggesting the risk of: a. Incorrect...
-
An independent auditor has completed substantive tests of balance sheet and income statement accounts, and now plans to begin procedures designed to determine whether there are any loss contingencies...
-
You were engaged to audit the financial statements of Ronlyn Corporation for the year ended June 30, 1999. On May 1, 1999, the corporation borrowed $500,000 from Second National Bank to finance plant...
-
In testing prepaid insurance, how does an auditor address rights and obligations?
-
What sources does an auditor use to test for overstated accounts payable, and how are those sources used?
-
(6 marks): Mr. Senior, age 70 has a life expectancy of 15 years. He owns a house worth 500,000; he is mortgage free. He is contemplating three options to supplement his monthly income: (1) a reverse...
-
A simple random sample of 220 university students were asked what pasta they usually order and with which sauce. The preferences of these respondents are summarised below: Sauce Bolognese Pasta...
-
An insurance company sells an automobile policy with a deductible of one unit. Let X be the amount of the loss having pmf Where c is a constant. Determine c and the expected value of the amount the...
-
Let and 2 denote the mean and variance of the random variable X. Determine E[(X )/] and E{[(X )/]2}.
-
In a woolen mill, 100-yard pieces are inspected. In the last 20 observations, the following numbers of flaws were found: (a) Compute the control limits of the c chart and draw this control chart. (b)...
-
Do you think that people give primarily for altruistic reasons or in order to receive benefits for themselves, including warm feelings, recognition, and social approval? Might the motivations differ...
-
The Corcoran Gallery of Art was established by Washington, DC, businessman William Wilson Corcoran, an early collector of contemporary American art. The gallery was opened in 1874 in a building that...
-
Hull House was founded in Chicago in 1889 by Jane Addams and Ellen Gates Starr, with the purpose of serving Chicago's immigrants and helping the city's poorest citizens improve their lives. Hull...
Study smarter with the SolutionInn App