Zorcs don't like other species. Zorcs like massive curve axes. Right now each of them is going to choose a suitable axe and show beings of other races entrenched nearby that they are not ready to peaceful cultural assimilation. There are n zorcs and m axes in total, and the i-th zorc wants to take an axe with the weight not less than ai and the curvature not less than bi, while the j-th axe has the weight wjand the curvature cj. Zorcs don't like programming problems. Zorcs like massive curve axes. So it's your task to determine which zorc must choose which axe.
Output
Output n integers, the i-th of which must be the number of axe that should be given to the i-th zorc to fulfill all his requirements. Of course, the same axe can't be given to two different zorcs.
If there is no possibility to distribute axes, fulfilling all requirements of all zorcs, output a single number - 1 instead of that.
题意:给你n对数 m对数 找出对应的下标 使得n[i]的x和y都小于等于m[i]的x和y 输出方案 不存在输出-1
题解:将n和m都从大到小排序 然后for n 对于每个n 将大于等于当前对x的m全部加到set里面 然后随便找一个my比当前y大的即可 如果不存在 -1
#include
#include
#include
#include
#include
using namespace std;
struct node{
int x,y,lab;
bool operator<(const node& a)const{
if(x==a.x&&y==a.y)return laba.y;
return x>a.x;
}
}e[200005],e1[200005];
int ans[200005];
struct nodes{
int y,lab;
bool operator<(const nodes& a)const{
if(y==a.y)return labsp;
multiset::iterator it,it1;
int main(){
int n,m,i,j,num,flag=1;
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d%d",&e[i].x,&e[i].y);
e[i].lab=i;
}
sort(e+1,e+1+n);
scanf("%d",&m);
for(i=1;i<=m;i++){
scanf("%d%d",&e1[i].x,&e1[i].y);
e1[i].lab=i;
}
sort(e1+1,e1+1+m);
nodes f;
int now=1;
for(i=1;i<=n;i++){
while(e1[now].x>=e[i].x&&now<=m){
f.y=e1[now].y;
f.lab=e1[now].lab;
sp.insert(f);
now++;
}
f.y=e[i].y;
f.lab=e[i].lab;
sp.insert(f);
it=sp.find(f);
it1=sp.end();
it1--;
if(it==it1){
if(it!=sp.begin()){
it--;
if((*it).y>=f.y){
ans[f.lab]=(*it).lab;
sp.erase(it);
it1=sp.find(f);
sp.erase(it1);
}
else{
flag=0;
break;
}
}
else{
flag=0;
break;
}
}
else{
if(it!=sp.begin()){
it--;
if((*it).y>=f.y){
ans[f.lab]=(*it).lab;
sp.erase(it);
it1=sp.find(f);
sp.erase(it1);
}
else{
it++;
it++;
ans[f.lab]=(*it).lab;
sp.erase(it);
it1=sp.find(f);
sp.erase(it1);
}
}
else{
it++;
ans[f.lab]=(*it).lab;
sp.erase(it);
it1=sp.find(f);
sp.erase(it1);
}
}
}
if(!flag)printf("-1\n");
else{
for(i=1;i<=n;i++)printf("%d ",ans[i]);
printf("\n");
}
return 0;
}