#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
const int N=100000+5;
struct node
{
int st,ed,id;
friend bool operator < (node n1,node n2)
{
return n2.ed<n1.ed;
}
}p[N];
priority_queue<node>q;
bool cmp(node x,node y)
{
return x.st<y.st;
}
int main()
{
int _,n,i,j,cnt,use[N],go[N],f;
scanf("%d",&_);
while(_--)
{
scanf("%d",&n);
memset(use,0,sizeof(use));
f=1;
for(i=0;i<n;i++)
scanf("%d",&p[i].st);
for(i=0;i<n;i++)
{
scanf("%d",&p[i].ed);
p[i].id=i+1;
}
sort(p,p+n,cmp);
while(!q.empty()) q.pop();
for(i=0,j=0,cnt=0;i<n;i++)
{
while(j<n&&p[j].st==i)
q.push(p[j++]);
while(!q.empty()&&q.top().ed<i)
{
q.pop();
}
if(q.empty()) break;
go[cnt++]=q.top().id;
q.pop();
}
printf("%d\n",cnt);
for(i=0;i<cnt;i++)
{
use[go[i]]=1;
if(f==1) {printf("%d",go[i]);f=0;}
else printf(" %d",go[i]);
}
for(i=1;i<=n;i++)
{
if(use[i]==0)
{
if(f==1) {printf("%d",i);f=0;}
else printf(" %d",i);
}
}
printf("\n");
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-12-28 09:20:47