http://codeforces.com/contest/1075/problem/B

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 — nnriders.

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 <bits/stdc++.h>
using namespace std; const int maxn = 300010;
int n, m;
long long pos[maxn], dir[maxn];
int cnt1 = 0, cnt = 0; struct Node{
long long dis;
long long num;
}car[maxn]; int main() {
scanf("%d%d", &n, &m);
for(int i = 1; i <= m + n; i ++)
cin >> pos[i];
for(int i = 1; i <= n + m; i ++) {
cin >> dir[i];
if(dir[i] == 1) {
cnt1 ++;
car[cnt1].dis = pos[i];
}
} for(int i = 1; i <= n + m; i ++) {
if(m == 1) {
printf("%d\n", n + m - 1);
return 0;
}
if(pos[i] < car[1].dis)
car[1].num ++;
else if(pos[i] > car[cnt1].dis)
car[cnt1].num = car[cnt1].num + 1; else if(dir[i] == 1)
cnt ++;
else if(pos[i] * 2 > car[cnt].dis + car[cnt + 1].dis)
car[cnt + 1].num ++;
else car[cnt].num ++;
} for(int i = 1; i <= cnt1; i ++) {
cout << car[i].num;
printf("%s", i != cnt1 ? " " : "\n");
}
return 0;
}

  

最新文章

  1. 多种坐标系之间的转换 Proj.NET和DotSpatial
  2. sqlServer下展示某库中所有的表
  3. CentOS下 MySQL5.7 详细的部署安装流程
  4. python 取两数的百分比
  5. ArcGIS 读写lyr层文件
  6. Android:DES加密
  7. 在企业级开发中使用Try...Catch...会影响效率吗?
  8. nginx 3.nginx+fastcgi
  9. poj 1273 Drainage Ditches_最大流模版
  10. 用php进行md5解密的源码,亲测可用
  11. (转自知乎https://www.zhihu.com/question/20794107)动态代理
  12. vue组件-构成组件-父子组件相互传递数据
  13. exec存储过程示例
  14. python全栈开发 * 23 面向对象 知识点汇总 * 180704
  15. ubuntu16.04下python2、python3环境选择与python升级(pip版本切换)
  16. RxSwift学习笔记8:filter/distinctUntilChanged/single/elementAt/ignoreElements/take/takeLast/skip/sample/debounce
  17. PAT甲题题解-1073. Scientific Notation (20)-字符串处理
  18. IT零起步-CentOS6.4部署OpenVPN服务器
  19. [日常] Linux使用diff来比较目录
  20. (转)SSIS处理导入数据时, 存在的更新, 不存在的插入

热门文章

  1. raspberrypi&amp;linux
  2. Android(java)学习笔记75:ListViewProject案例(ListView + BaseAdapter + CheckBox)
  3. PHP implode() 函数
  4. 安装配置JDK1.8开发环境以及配置java环境变量的步骤
  5. 十一、Shell 文件包含
  6. 服务发现与注册-Eureka
  7. OpenFaceswap 入门教程(2):软件使用篇!
  8. JZOJ 3223. 【HBOI2013】Ede的新背包问题
  9. Ecshop之ajax修改表里的状态(函数化处理)
  10. hive的常用HQL语句