Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) B 1075B (思维)
1 second
256 megabytes
standard input
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.
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 .
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).
3 1
1 2 3 10
0 0 1 0
3
3 2
2 3 4 5 6
1 0 0 0 1
2 1
1 4
2 4 6 10 15
1 1 1 1 0
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 (思维)的更多相关文章
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)
这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...
- 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)\), 现 ...
- 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, ...
- 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的矩阵中的左下角,放置一个车(车可以移动到同一行或同一列),放置一些墙,竖的占据 ...
- 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, ...
- Lyft Level 5 Challenge 2018 - Final Round Div. 1没翻车记
夜晚使人着迷.没有猝死非常感动. A:显然对于水平线段,只有横坐标的左端点为1的时候才可能对答案产生影响:对于竖直直线,如果要删一定是删去一段前缀.枚举竖直直线删到哪一条,记一下需要删几条水平线段就可 ...
- [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 ...
- Lyft Level 5 Challenge 2018 - Elimination Round
A. King Escape 签. #include <bits/stdc++.h> using namespace std; ], y[]; int f1(int X, int Y) { ...
- Lyft Level 5 Challenge 2018 - Elimination Round翻车记
打猝死场感觉非常作死. A:判一下起点和终点是否在其两侧即可. #include<iostream> #include<cstdio> #include<cmath> ...
随机推荐
- Python数据库(三)-使用sqlalchemy创建表
首先需要安装sqlalchemy根据所需情况调用数据库接口,对数据库进行操作pymysql:mysql+pymysql://<username>:<password>@< ...
- PowerDesigner中CDM和PDM如何定义外键关系
有A.B两张表(实体),各自有id作为主键,两表是一一对应关系.但略有不同: A表一条记录可以对应0或1条B表记录,B表一条记录必须对应唯一条A表记录. 这样的关系如何在CDM或PDM中定义? 在最后 ...
- 面试题:struts 值栈 有用
一. 核心部分 1. [核心试题]完成当天课堂练习 2. [多选题] 阅读如下代码中,下列哪种方式可以在页面正确迭代获取集合中的数据 (ABC) public String add(){ ValueS ...
- elasticsearch 6.2.4 安装 elasticsearch-analysis-ik 分词器 (windows 10下)
访问 https://github.com/medcl/elasticsearch-analysis-ik 找 releases 找到对应的 es 版本 下载 elasticsearch-analy ...
- HDU3686 Traffic Real Time Query
按照vdcc缩点之后一条边只会属于一个新的点集,由于这棵树上满足(不是割点) - (割点) - (不是割点)的连接方法,所以求两条边之间的必经点就是(树上距离 / 2),倍增跳lca即可 考虑到缩点后 ...
- 利用HTML5 与CSS3 做的放大镜
利用HTML5 与CSS3 做的放大镜 html结构 <div class="wrap"> <div class="move"> < ...
- PHP微信分享
注意 : 分享需要认证微信订阅号或者服务号. php 代码(thinkphp): $appid='xxx'; $appsecret='xxxx'; $timestamp = time(); ...
- Clos Network
1952年,Charles Clos 设计出了一种多级的交换架构,用多级的小型交换机阵列来构建一张大的无阻塞的网络.在此之前,要实现“无阻塞的架构”,只能采用NxN的Cross-bar方式. 而Clo ...
- 删除GHOST中win7桌面IE删不掉的解决办法
打开Win+R 运行regedit 依次打开: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Deskto ...
- Java Collection.RP
在 Java2中,有一套设计优良的接口和类组成了Java集合框架Collection,使程序员操作成批的数据或对象元素极为方便.这些接口和类有很多对抽象数据类型操作的API,而这是我们常用的且在数据结 ...