Taxi drivers and Lyft

G - Taxi drivers and Lyft

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 mm taxi drivers in the city, who every day transport the rest of the city residents — nn 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 ii the number aiai — the number of riders that would call the ii-th taxi driver when all drivers and riders are at their home?

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

Input

The first line contains two integers nn and mm (1≤n,m≤1051≤n,m≤105) — number of riders and taxi drivers.

The second line contains n+mn+m integers x1,x2,…,xn+mx1,x2,…,xn+m (1≤x1<x2<…<xn+m≤1091≤x1<x2<…<xn+m≤109), where xixi is the coordinate where the ii-th resident lives.

The third line contains n+mn+m integers t1,t2,…,tn+mt1,t2,…,tn+m (0≤ti≤10≤ti≤1). If ti=1ti=1, then the ii-th resident is a taxi driver, otherwise ti=0ti=0.

It is guaranteed that the number of ii such that ti=1ti=1 is equal to mm.

Output

Print mm integers a1,a2,…,ama1,a2,…,am, where aiai is the answer for the ii-th taxi driver. The taxi driver has the number ii if among all the taxi drivers he lives in the ii-th smallest coordinate (see examples for better understanding).

Examples

Input

3 1
1 2 3 10
0 0 1 0

Output

3 

Input

3 2
2 3 4 5 6
1 0 0 0 1

Output

2 1 

Input

1 4
2 4 6 10 15
1 1 1 1 0

Output

0 0 0 1 

Note

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

In the second example, the first taxi driver lives at the point with the coordinate 22, and the second one lives at the point with the coordinate 66. Obviously, the nearest taxi driver to the rider who lives on the 33 coordinate is the first one, and to the rider who lives on the coordinate 55 is the second one. The rider who lives on the 44 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.

题意:有n个乘客,m辆出租车,每个单位都对应一个坐标,问每辆出租车最多可以拉几个乘客,其中乘客只能乘坐离自己位置最近的出租车。

#include<iostream>
#include<cstring>
using namespace std;
struct haha
{
    int left;
    int right;
    int pos;
    int biaoji;

};
int ans[200005];
haha ig[200005];
int main()
{

    int n,m;

    while(cin>>n>>m)
    {
        memset(ans,0,sizeof(ans));
        for(int i=0; i<n+m; i++)
            cin>>ig[i].pos;
        for(int i=0; i<n+m; i++)
            cin>>ig[i].biaoji;
        int we=-1;
        for(int i=0; i<n+m; i++)//按照坐标从小到大找每个人左边最近的车的坐标,记录为left。
        {
            if(ig[i].biaoji)
                we=i;
            else
                ig[i].left=we;
        }
        we=-1;
        for(int i=n+m-1; i>=0; i--)//按照坐标从大到小找每个人右边最近的车的坐标,记录为right。
        {
            if(ig[i].biaoji)
                we=i;
            else
                ig[i].right=we;
        }

        for(int i=0; i<n+m; i++)
        {
            if(ig[i].biaoji==0)
            {
                if(ig[i].left==-1)//如果为最左边的人,那他右边最近的车加1。
                    ans[ig[i].right]++;
                else if(ig[i].right==-1)//如果=为最右边的人,那他左边最近的车加1.
                    ans[ig[i].left]++;
                else if(ig[i].left!=-1&&ig[i].right!=-1)
                {
                    int m1=ig[i].pos-ig[ig[i].left].pos;//非两边的人需要左右两个最近的车的位置进行比较,注意left和right只是保存的下标不是真正的距离。
                    int m2=ig[ig[i].right].pos-ig[i].pos;
                    if(m1<=m2)
                        ans[ig[i].left]++;
                    else
                        ans[ig[i].right]++;
                }
            }
        }
        for(int i=0; i<n+m; i++)
        {
            if(ig[i].biaoji)
            {
                cout<<ans[i]<<" ";
            }
        }
        cout<<endl;

    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/zhouchenghao123/article/details/83863867
今日推荐