Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) B 1075B (思维)

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 11 2 3 100 0 1 0

Output

Copy

3 

Input

Copy

3 22 3 4 5 61 0 0 0 1

Output

Copy

2 1 

Input

Copy

1 42 4 6 10 151 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=1000000007;
const int inf = 0x3f3f3f3f;
void read() {freopen("in.txt","r",stdin);}
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)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=200010;
int n,m,L[maxn],R[maxn],ans[maxn],pos[maxn],dir[maxn];
int main() {
    //read();
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n+m;i++) scanf("%d",&pos[i]);
    for(int i=1;i<=n+m;i++) scanf("%d",&dir[i]);
    for(int i=1;i<=n+m;i++) {//从1开始,很巧妙,预处理也很巧
        if(dir[i]) L[i]=i;
        else L[i]=L[i-1];
    }
    R[n+m+1]=n+m+1;
    for(int i=n+m;i>=1;i--) {
        if(dir[i]) R[i]=i;
        else R[i]=R[i+1];
    }
    for(int i=1;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=1;i<=n+m;i++) {
        if(dir[i]) printf("%d ",ans[i]);
    }
}

原文地址:https://www.cnblogs.com/ACMerszl/p/9942675.html

时间: 2024-11-09 10:26:21

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

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

A. The King's Race 签. 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 #define ll long long 5 ll n, x, y; 6 7 ll f(ll a, ll b) 8 { 9 return max(abs(a - x), abs(b - y)); 10 } 11 12 int main() 13 { 14 while (scanf("%lld%lld%lld", &n

Lyft Level 5 Challenge 2018 - Elimination Round翻车记

打猝死场感觉非常作死. A:判一下起点和终点是否在其两侧即可. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; int read() { int x=0,f=1;char c=getchar(); while (c<'0'

Lyft Level 5 Challenge 2018 - Elimination Round

A. King Escape 签. 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int n, x[3], y[3]; 5 6 int f1(int X, int Y) 7 { 8 return X - Y - x[2] + y[2]; 9 } 10 11 int f2(int X, int Y) 12 { 13 return x[2] + y[2] - X - Y; 14 } 15 16 bool ok() 17 { 18 //i

Codeforces Round #424 (Div. 2) D 思维 E set应用,树状数组

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) D. Office Keys 题意:一条直线上,有个办公室坐标 p,有 n个人在a[i],有 k把钥匙在b[i],每个人必须拿到一把钥匙,然后到办公室.问怎么安排花的时间最短. tags:还是不懂套路啊..其实多画两下图就能够感觉出来,2333 关键是要看出来,n个人拿的 n把钥匙应该是连续的. 然后,就是瞎暴力.. #include<bits/stdc++.h> usi

Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round) D. Peculiar apple-tree

D. Peculiar apple-tree time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained i

Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) A. Contest for Robots(思维题)

Polycarp is preparing the first programming contest for robots. There are nn problems in it, and a lot of robots are going to participate in it. Each robot solving the problem ii gets pipi points, and the score of each robot in the competition is cal

Codeforces Round #541 (Div. 2) E 字符串 + 思维 + 猜性质

https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1+s[1]+s1+...+s1+s[size-1]+s1+s[size]+s1\),求n个字符串依次相乘后最长连续字符相同的子序列长度 题解 鬼畜的题意 or 难以优化的复杂度,都需要观察性质才能做,第二串要插入第一个串每个字符之间,可以看出字符数增长的速度很快,所以并不能把整个字符存下来 只看一种

Codeforces Round #546 (Div. 2) D 贪心 + 思维

https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则,假如u在v相邻前面,那么u和v可以交换位置,问你是队列最后一个人的时候你最前可以换到前面哪里 题解 因为相邻才能换,所以最后一个换到前面一定是一步一步向前走,所以不存在还要向后走的情况 设最后一个为u,假设前面有一个能和u换位置的集合,那么需要将这些点尽量往后移动去接u 假设前面有一个不能和u换位置的集合S,

Codeforces Round #581 (Div. 2)D(思维,构造,最长非递减01串)

#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;char s[100007];int main(){ cin>>s+1; int n=strlen(s+1); int cnt=0; for(int i=n;i>=1;--i){//从后向前,保证后面的解都是合法的情况下 if(s[i]=='1'){//如果当前位置的数字是1 if(cnt)//i后面1的个数小于0的个数,此时如果把i位