Taxi drivers and Lyft
Contest: Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2)
Difficulty rating: 1200
Tags: implementation, sortings

Palo Alto is an unusual city because it is an endless coordinate line. It is also known for the office of Lyft Level 5.

Lyft has become so popular so that it is now used by all $$$m$$$ taxi drivers in the city, who every day transport the rest of the city residents — $$$n$$$ riders.

Each resident (including taxi drivers) of Palo-Alto lives in its unique location (there is no such pair of residents that their coordinates are the same).

The Lyft system is very clever: when a rider calls a taxi, his call does not go to all taxi drivers, but only to the one that is the closest to that person. If there are multiple ones with the same distance, then to taxi driver with a smaller coordinate is selected.

But one morning the taxi drivers wondered: how many riders are there that would call the given taxi driver if they were the first to order a taxi on that day? In other words, you need to find for each taxi driver $$$i$$$ the number $$$a_{i}$$$ — the number of riders that would call the $$$i$$$-th taxi driver when all drivers and riders are at their home?

The taxi driver can neither transport himself nor other taxi drivers.

Input format:
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n,m \le 10^5$$$) — number of riders and taxi drivers.

The second line contains $$$n + m$$$ integers $$$x_1, x_2, \ldots, x_{n+m}$$$ ($$$1 \le x_1 < x_2 < \ldots < x_{n+m} \le 10^9$$$), where $$$x_i$$$ is the coordinate where the $$$i$$$-th resident lives.

The third line contains $$$n + m$$$ integers $$$t_1, t_2, \ldots, t_{n+m}$$$ ($$$0 \le t_i \le 1$$$). If $$$t_i = 1$$$, then the $$$i$$$-th resident is a taxi driver, otherwise $$$t_i = 0$$$.

It is guaranteed that the number of $$$i$$$ such that $$$t_i = 1$$$ is equal to $$$m$$$.

Output format:
Print $$$m$$$ integers $$$a_1, a_2, \ldots, a_{m}$$$, where $$$a_i$$$ is the answer for the $$$i$$$-th taxi driver. The taxi driver has the number $$$i$$$ if among all the taxi drivers he lives in the $$$i$$$-th smallest coordinate (see examples for better understanding).

Constraints:
Time limit: 1.0 s
Memory limit: 256.0 MB

Note:
In the first example, we have only one taxi driver, which means an order from any of $$$n$$$ riders will go to him.

In the second example, the first taxi driver lives at the point with the coordinate $$$2$$$, and the second one lives at the point with the coordinate $$$6$$$. Obviously, the nearest taxi driver to the rider who lives on the $$$3$$$ coordinate is the first one, and to the rider who lives on the coordinate $$$5$$$ is the second one. The rider who lives on the $$$4$$$ coordinate has the same distance to the first and the second taxi drivers, but since the first taxi driver has a smaller coordinate, the call from this rider will go to the first taxi driver.

In the third example, we have one rider and the taxi driver nearest to him is the fourth one.

Example input:
3 1
1 2 3 10
0 0 1 0

Example output:
3

Example input:
3 2
2 3 4 5 6
1 0 0 0 1

Example output:
2 1

Editorial:
Let's find for each rider the taxi driver that will get his call.
To do this we can find for each rider the nearest taxi driver at right and the nearest taxi driver at left. Let's define the nearest taxi driver at left for $$$i$$$-th citizen as $$$l_i$$$ and at the right as $$$r_i$$$.
The computations can be done with the following algorithm:
Let's define $$$l_0=0$$$ and $$$r_{n+m+1}=n+m+1$$$. And $$$x_0=-2*10^9$$$, $$$x_{n+m+1} = 2*10^{9}$$$.
In order to find $$$l_i$$$ for each $$$i$$$ we should iterate through the citizens from $$$1$$$ to $$$n+m$$$. If the $$$i$$$-th citizen is a taxi driver, then he/she is obviously the nearest taxi driver to himself/herself. If the $$$i$$$-th citizen is a rider, then $$$l_i=l_{i-1}$$$
In order to find $$$r_i$$$ for each $$$i$$$ we should iterate through the citizens from $$$n+m$$$ to $$$1$$$. If the $$$i$$$-th citizen is a taxi driver, then $$$r_i=i$$$, else $$$r_i=r_{i+1}$$$.
Now it's time to compute the answer.
Let's denote $$$b_i$$$ as the number of citizens, whose calls the $$$i$$$-th citizen will get (if the $$$i$$$-th citizen is a rider, then $$$b_i=0$$$).
In order to do compute the values of array $$$b$$$ we should iterate through the citizens from $$$1$$$ to $$$n+m$$$. If the $$$i$$$-th citizen is a rider, then if the $$$x_{r_i}-x_i<x_i-x_{l_i}$$$ (distance between the nearest taxi driver at right and the $$$i$$$-th citizen is smaller than distance between the nearest taxi driver at the left and the citizen), then taxi driver $$$r_i$$$ will get the call, otherwise the taxi driver $$$l_i$$$ will get the call. So if $$$x_{r_i}-x_i<x_i-x_{l_i}$$$, then $$$b_{r_i}:=b_{r_i}+1$$$, else $$$b_{l_i}:=b_{l_i}+1$$$.
In order to print out the answer we iterate through the citizens from $$$1$$$ to $$$n+m$$$. If the $$$i$$$-th citizen is a taxi driver, than we should print $$$b_i$$$.
The algorithm iterates through the array four times, so overall complexity is $$$O(n+m)$$$