传送门
题意:
思路: 对于每个人都有个二元组(x,y)(x,y)(x,y),从题意中提取有效信息就是:当(x1,y1)(x_1,y_1)(x1,y1)的最大值大于(x2,y2)(x_2,y_2)(x2,y2)的最大值,(x1,y1)(x_1,y_1)(x1,y1)的最小值大于(x2,y2)(x_2,y_2)(x2,y2)的最小值,那么(x2,y2)(x_2,y_2)(x2,y2)就是符合条件的。这样我们可以对于hhh和www,如果h<wh<wh<w,那么就交换hhh和www。让后按照hhh排序,从头维护一个www的最小值和对应的ididid,让后在hhh不相等的时候更新就好啦。
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].l+tr[u].r>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;int n;
int ans[N];
struct Node
{int x,y;int id;bool operator < (const Node &W) const{if(x!=W.x) return x<W.x;else return y<W.y;}
}q[N];int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);int _; scanf("%d",&_);while(_--){scanf("%d",&n);for(int i=1;i<=n;i++){ans[i]=-1;scanf("%d%d",&q[i].x,&q[i].y); q[i].id=i;if(q[i].x<q[i].y) swap(q[i].x,q[i].y);}sort(q+1,q+1+n);int mi=INF,id=-1;for(int i=1;i<=n;i++){int x=q[i].x,now=i;while(i<=n&&x==q[i].x){if(mi!=INF&&mi<q[i].y) ans[q[i].id]=id;i++;}i--;if(mi>q[now].y) mi=q[now].y,id=q[now].id;}for(int i=1;i<=n;i++) printf("%d ",ans[i]);puts("");}return 0;
}
/**/