https://ac.nowcoder.com/acm/contest/54877/D
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 2e5 + 100;
pair<ll,ll> hm[N];
pair<ll,pair<ll,ll> > ct[N];
ll kans[N];//此时第几个猫猫的值
int main() {
ll n,m;
scanf("%lld%lld",&n,&m);
for (ll i = 1;i <= n;i++) {//猫猫友善 X
scanf("%lld",&ct[i].first);
}
for (ll i = 1;i <= n;i++) {
scanf("%lld",&ct[i].second.first);//猫猫期望 Y
ct[i].second.second = i;//坐标
}
for (ll i = 1;i <= m;i++) {
scanf("%lld",&hm[i].second);//主人友善 tY
}
for (ll i = 1;i <= m;i++) {
scanf("%lld",&hm[i].first);//主人期望 tX
}
sort(ct + 1,ct + n + 1);//猫猫友善从小到大
sort(hm + 1,hm + m + 1);//主人期望从小到大
ll ans = -1;
ll idx = 0;
for (ll i = 1;i <= n;i++)//离线询问全部的猫;;此时猫就是坐标的黑点
{
//主人期望所有符合的,,也就是二维坐标所有左边的x点;
while((idx < m) && (hm[idx + 1].first <= ct[i].first)) {
idx++;
//更新此时主人友善的最大值
ans = max(ans,hm[idx].second);
}
//如果友善ty点大于猫猫的y,就存入
if (ans >= ct[i].second.first) {
kans[ct[i].second.second] = ans;
} //否则没有找到
else {
kans[ct[i].second.second] = -1;
}
}
for (ll i = 1;i <= n;i++) {
printf("%lld ",kans[i]);
}
return 0;
}