排序+暴力
cpp
#include<bits/stdc++.h>
using namespace std;
int n;
const int N = 1e3+5;
struct node{
int l,r,h,pos;
bool operator<(node b){
if(h>b.h) return 1;
return h== b.h ? pos < b.pos : 0;
}
}sto[N];
int ans[N][2];
int main(){
cin >> n;
for(int i=1;i<=n;i++){
cin >> sto[i].h >> sto[i].l >> sto[i].r;
sto[i].pos = i;
}
sort(sto+1,sto+1+n);
for(int i=1;i<=n;i++){
int h = sto[i].h, l = sto[i].l ,r = sto[i].r,pos = sto[i].pos;
//cout << h << " " << l << " " << r << " " << endl;
int flagl = 1, flagr = 1;
for(int j=i+1;j<=n;j++){
if(h==sto[j].h) continue;
int ll = sto[j].l , rr = sto[j].r, ppos = sto[j].pos;
if(flagl){
if(l>ll&&l<rr){
ans[pos][0] = ppos; flagl = 0;
}
}
if(flagr){
if(r>ll&&r<rr){
ans[pos][1] = ppos; flagr = 0;
}
}
if(flagl==0 && flagr==0) break;
}
}
for(int i=1;i<=n;i++){
cout << ans[i][0] << " " << ans[i][1] << endl;
}
return 0;
}