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. Java enum(枚举)使用详解之四

    用法五:实现接口 所有的枚举都继承自java.lang.Enum类.由于Java 不支持多继承,所以枚举对象不能再继承其他类. public interface Behaviour { void pr ...

  2. JavaSwing文件选择器 JFileChooser的使用

    先看效果吧! 说明:选择文件或者文件夹.本例子就直接在控制台输出文件或者文件夹的路径.实际开发中,就可以将文件或文件夹的路径封装为File的实例来使用了. package test; import j ...

  3. adb pull 和 adb push

    1. 操作单个文件 通过adb push,则可将文件添加到SD卡中.如果想在push的时候修改文件名称的话,只需要修改push的第二个参数改成完整路径(目录+文件名),如/sdcard/test-0. ...

  4. memset,memcpy,strcpy的使用与区别

    1.memset 原型:   extern void *memset(void *buffer, int c, int count); 功能:   把buffer所指内存区域的前count个字节设置成 ...

  5. os.path.join合并 os.path.dirname返回上一级目录 os.path.exists(path) os.stat('path/filename')获取文件/目录信息

    import os str1 = "grsdgfd" str2 = "wddf" str3 = "gddgs" # print(str1 + ...

  6. android中finish和system.exit方法退出的区别

    finish只是将此activity推向后台,并没有释放资源. 而system.exit则是杀死进程,会释放资源

  7. Hbuilder实用技巧(转)

    Hbuilder实用技巧 原创 2016年05月19日 10:25:42 标签: hbuilder 操作 16551 1. Q:怎么实现代码追踪? A:在编辑代码时经常会出现需要跳转到引用文件或者变量 ...

  8. resize函数有五种插值算法

    转自http://blog.csdn.net/fengbingchun/article/details/17335477 最新版OpenCV2.4.7中,cv::resize函数有五种插值算法:最近邻 ...

  9. 初识Servlet(JSP)

    Java Servlet 是运行在 Web 服务器或应用服务器上的程序,它是作为来自 Web 浏览器或其他 HTTP 客户端的请求和 HTTP 服务器上的数据库或应用程序之间的中间层.  Servle ...

  10. ubuntu nvidia驱动+cuda9.0

    https://blog.csdn.net/fdqw_sph/article/details/78745375