2292 - I2P(I)2020_Chen_HW3 Scoreboard

Time

2021/03/23 23:00:00 2021/03/30 23:59:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
12132 too many watermelons
12125 Tired janitor

12132 - too many watermelons   

Description

Ovuvuevuevue Enyetuenwuevue Ugbemugbem Osas wants to eat watermelon. But the watermelons are stored in a cylindrical(圓柱狀) box.


He has n watermelons and each one has a specific index denote as ai.

Osas wants to eat a watermelon indexed ai.

But if the watermelon indexed ai is not on the top,

he needs to eat all watermelon above the watermelon indexed ai.

Osas also has a list which is the order of watermelons he wants to eat which denoted as bi.

The length of the list is also n and all bi 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 a1 ~ an which denote as the index of watermelons from top to bottom .( 1 <= ai <= n )

 

Third line contains n integer b~ bn which denote as the order of watermelons  that Osas' wants to eat.( 1 <= bi <= 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

Sample Output  Download

Tags




Discuss




12125 - Tired janitor   

Description

There were n rows of seats in the classroom. Each row of seats littered with ai unit of trash. 

For example: first row contained a1 unit of trash

The janitor wanted to know how many units of trash were littered among row l to row r?

For example: If janitor ask you about row l = 3 to row r = 6. You should answer a3 + a4 + a5 + a6 unit of trash.

There will be q queries, help janitor  find out the answer so janitor  can clean up the class room.

Note that because janitor  is furious about picking up trash, each number will be follow by a symbol " (/`A`)/ ~I__I " without quotation mark and then there is a blank to separate from the next number.

Note that if you use a loop to get the sum of al ~ ar at each query you will get an Time limit exceed. 

You can use prefix sum to solve this problem

Input

input contains several lines.

First line contains two integer n(1 <= n <= 106), q(1 <= q <= 105) -- the number of rows and the number of queries.

Second line contains n integer a1 ~ an (0 <= ai <= 109), and each interger followed by a symbol " (/`A`)/ ~I__I " and then there is a blank to separate from the next number.

The following q lines each lines contains two integers l, r ( 1 <= l <= r <= n )

Output

output contain q lines, to each query output the sum of al ~ ar. remember to print \n at the end of each line.

Sample Input  Download

Sample Output  Download

Tags




Discuss