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]);
}
}

最新文章

  1. 201301 JAVA题目0-1级
  2. C++Socket编程总结 [转]
  3. Android之线程终止
  4. HTML5学习之FileReader接口
  5. rabbitmq 测试
  6. ng-repeat-start ng-repeat-end 的使用
  7. ARP网关占用
  8. 1084: [SCOI2005]最大子矩阵
  9. elastalert
  10. 【转载】BlockingQueue
  11. WPF中任务栏只显示主窗口
  12. dubbo常用配置及注意事项
  13. anaconda更新库命令
  14. 08 LaTeX学习系列之---Latex 的中文操作
  15. k8s部署prometheus
  16. jsp中的JSTL与EL表达式用法
  17. Python使用suds调用webservice报错解决方法:AttributeError: &#39;Document&#39; object has no attribute &#39;set&#39;
  18. chrome driver 下载
  19. Algorithm类介绍(core)
  20. PCL采样一致性算法

热门文章

  1. DDD学习笔录——领域驱动设计的常见误区(即错误的理解)
  2. C语言学习笔记--字符串
  3. Spring事务SPI及配置介绍
  4. Servlet开发中注意的细节问题
  5. Codeforces 1108F (MST Unification) (树上倍增 or 改进 kruksal)
  6. 【转】nginx location匹配规则
  7. opencv 基本数据结构
  8. 杭电ACM刷题(2):1005,Number Sequence 标签: 杭电acmC语言 2017-05-11 22:43 116人阅读
  9. 使用docker的kms服务器激活office2016专业增强版
  10. c语言中的const的作用及解析