B. Taxi drivers and Lyft
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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

Copy
3 1
1 2 3 10
0 0 1 0
Output

Copy
3 
Input

Copy
3 2
2 3 4 5 6
1 0 0 0 1
Output

Copy
2 1 
Input

Copy
1 4
2 4 6 10 15
1 1 1 1 0
Output

Copy
0 0 0 1 

看到这道题感觉很简单就是写不出来,队友都可快做出来了,后来看了大佬代码,真是美如画。

正反遍历预处理每个点的最近司机,然后再遍历判断即可

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
using namespace std;
#define debug(x) cout << "&&" << x << "&&" << endl;
#define lowbit(x) (x&-x)
#define mem(a,b) memset(a, b, sizeof(a));
typedef long long ll;
const ll mod=;
const int inf = 0x3f3f3f3f;
void read() {freopen("in.txt","r",stdin);}
ll powmod(ll a,ll b) {ll res=;a%=mod;for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//head const int maxn=;
int n,m,L[maxn],R[maxn],ans[maxn],pos[maxn],dir[maxn];
int main() {
//read();
scanf("%d%d",&n,&m);
for(int i=;i<=n+m;i++) scanf("%d",&pos[i]);
for(int i=;i<=n+m;i++) scanf("%d",&dir[i]);
for(int i=;i<=n+m;i++) {//从1开始,很巧妙,预处理也很巧
if(dir[i]) L[i]=i;
else L[i]=L[i-];
}
R[n+m+]=n+m+;
for(int i=n+m;i>=;i--) {
if(dir[i]) R[i]=i;
else R[i]=R[i+];
}
for(int i=;i<=n+m;i++) {
if(!dir[i]) {//如果是乘客,并且L[i]为0即没有左司机,或右司机>n+m并且左距离大于右距离
if(!L[i]||(R[i]<=n+m&&pos[i]-pos[L[i]]>pos[R[i]]-pos[i])) ans[R[i]]++;
else ans[L[i]]++;
}
}
for(int i=;i<=n+m;i++) {
if(dir[i]) printf("%d ",ans[i]);
}
}

Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) B 1075B (思维)的更多相关文章

  1. Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)

    这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...

  2. Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2)---ABC

    A---The King's Race http://codeforces.com/contest/1075/problem/A 题意: 一个人在\((1,1)\), 一个人在\((n,n)\), 现 ...

  3. Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2)

    A. The King's Race 签. #include <bits/stdc++.h> using namespace std; #define ll long long ll n, ...

  4. Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) C. The Tower is Going Home(思维+双指针)

    https://codeforces.com/contest/1075/problem/C 题意 一个宽为1e9*1e9的矩阵中的左下角,放置一个车(车可以移动到同一行或同一列),放置一些墙,竖的占据 ...

  5. Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) A. The King's Race

    http://codeforces.com/contest/1075/problem/A On a chessboard with a width of nn and a height of nn, ...

  6. Lyft Level 5 Challenge 2018 - Final Round Div. 1没翻车记

    夜晚使人着迷.没有猝死非常感动. A:显然对于水平线段,只有横坐标的左端点为1的时候才可能对答案产生影响:对于竖直直线,如果要删一定是删去一段前缀.枚举竖直直线删到哪一条,记一下需要删几条水平线段就可 ...

  7. [Lyft Level 5 Challenge 2018 - Elimination Round][Codeforces 1033D. Divisors]

    题目链接:1033D - Divisors 题目大意:给定\(n\)个数\(a_i\),每个数的约数个数为3到5个,求\(\prod_{i=1}^{n}a_i\)的约数个数.其中\(1 \leq n ...

  8. Lyft Level 5 Challenge 2018 - Elimination Round

    A. King Escape 签. #include <bits/stdc++.h> using namespace std; ], y[]; int f1(int X, int Y) { ...

  9. Lyft Level 5 Challenge 2018 - Elimination Round翻车记

    打猝死场感觉非常作死. A:判一下起点和终点是否在其两侧即可. #include<iostream> #include<cstdio> #include<cmath> ...

随机推荐

  1. Python函数(五)-高阶函数

    函数接收的参数可以是数字,字符串,列表,元组,字典,集合,也可以是另一个函数,那么这个接收一个函数作为参数的函数就称为高阶函数 # -*- coding:utf-8 -*- __author__ = ...

  2. node install webpack -cli webpack4.xxxx

    webpack 4.xx 版本 分离了 webpack-cli ; 安装webpack4.xx 需要再安装webpack-cli;

  3. ListView显示Sqlite的数据

    在安卓中,ListView和Sqlite都是十分常用的.这次我们来结合这个两个知识点写一个Demo. 功能:吧SQLite中的数据用ListView显示出来. 先看截图吧 首先是数据库 然后是运行截图 ...

  4. Android ScrollView 内部控件 layout_margin失效的解决方法

    在<ScrollView> 的<LinearLayout  >属性里面加入android:layout_gravity="top" <LinearLa ...

  5. Navicat MySQL安装

    1 下载安装包 点击下载安装包 2 解压安装包(解压后有三个文件) 第一个 Crack 是注册文件 第二个 chinese.rar 是汉化包 第三个 navicat_trial.exe 是安装程序 3 ...

  6. 大O表示法总结

    大O符号用于计算机科学来描述算法的性能或复杂性.Big O特别描述了最坏的情况,可以用算法来描述所需的执行时间或使用的空间(例如在内存或磁盘上). 任何读过Programming Pearls(编程珠 ...

  7. #pragma pack()用法详解

    博客转载自:http://blog.csdn.net/lime1991/article/details/44536343 1.什么是对齐?为什么要对齐? 现代计算机中内存空间都是按照byte划分的,从 ...

  8. GCD 学习(四) dispatch_group

    如果想在dispatch_queue中所有的任务执行完成后在做某种操作,在串行队列中,可以把该操作放到最后一个任务执行完成后继续,但是在并行队列中怎么做呢.这就有dispatch_group 成组操作 ...

  9. Luogu 3625 [APIO2009]采油区域

    想了很久的dp,看了一眼题解之后感觉自己被安排了. 发现从一个矩形中选择三个不相交的正方形一共只有六种取法. 那么我们可以处理出四个值: $f_{i, j}$分别表示以$(i, j)$为右下角,左下角 ...

  10. Visual Studio2012快捷键总结

    (1)如何设置更改快捷键 1.进入工具----选项  对话框 2.选择  环境---->键盘 3.在 [显示命令包含] 下面的对话框中输入“对齐”关键字,然后就会在这个编辑框下面一个文本窗口中显 ...