Language: C

#include<stdio.h>
#include<string.h>
const int Maxn=200010;
int max(int x,int y){return x>y?x:y;}
int n,a[Maxn],b[Maxn],c[Maxn],L[Maxn],R[Maxn],cc[Maxn],ans[Maxn];
struct Node
{
	int l,r,lc,rc,mx,p,tag;
}tr[Maxn<<1];
int tot=0;
void merge(int x)
{
	int lc=tr[x].lc,rc=tr[x].rc;
	tr[x].mx=max(tr[lc].mx,tr[rc].mx); 
	if(tr[x].mx==tr[lc].mx)tr[x].p=tr[lc].p;
	else tr[x].p=tr[rc].p;
} 
void w(int x,int v)
{
	tr[x].tag+=v;
	tr[x].mx-=v;
}
void down(int x)
{
	if(tr[x].tag)
	{
		int v=tr[x].tag;
		w(tr[x].lc,v);w(tr[x].rc,v);
		tr[x].tag=0;
	}
}
void build(int l,int r)
{
	int x=++tot;
	tr[x].l=l;tr[x].r=r;tr[x].tag=0;
	if(l==r)
	{
		tr[x].p=l;tr[x].mx=c[a[l]];
		return;
	}
	int mid=l+r>>1;
	tr[x].lc=tot+1;build(l,mid);
	tr[x].rc=tot+1;build(mid+1,r);
	merge(x);
}
void m2(int x,int l,int r,int v)
{
	if(tr[x].l==l&&tr[x].r==r){w(x,v);return;}
	int mid=tr[x].l+tr[x].r>>1,lc=tr[x].lc,rc=tr[x].rc;
	down(x);
	if(r<=mid)m2(lc,l,r,v);
	else if(l>mid)m2(rc,l,r,v);
	else m2(lc,l,mid,v),m2(rc,mid+1,r,v);
	merge(x);
}
void m3(int x,int p,int v)
{
	if(tr[x].l==tr[x].r)
	{
		ans[p]=v;tr[x].mx=-1;
		return;
	}
	int mid=tr[x].l+tr[x].r>>1,lc=tr[x].lc,rc=tr[x].rc;
	down(x);
	if(p<=mid)m3(lc,p,v);
	else m3(rc,p,v);
	merge(x);
}
int Mx,P;
void m4(int x,int l,int r)
{
	if(tr[x].l==l&&tr[x].r==r)
	{
		if(tr[x].mx>Mx)
		{
			Mx=tr[x].mx;
			P=tr[x].p;
		}
		return;
	}
	int mid=tr[x].l+tr[x].r>>1,lc=tr[x].lc,rc=tr[x].rc;
	down(x);
	if(r<=mid)m4(lc,l,r);
	else if(l>mid)m4(rc,l,r);
	else m4(lc,l,mid),m4(rc,mid+1,r);
	merge(x);
}
int main()
{
	memset(c,0,sizeof(c));
	memset(cc,0,sizeof(cc));
	memset(L,-1,sizeof(L));
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);cc[a[i]]++;
		R[a[i]]=i;
		if(L[a[i]]==-1)L[a[i]]=i;
	}
	for(int i=1;i<=n;i++)scanf("%d",&b[i]),c[b[i]]++;
	for(int i=1;i<=n;i++)
	if(c[b[i]]>n-cc[b[i]])return puts("NO"),0;
	build(1,n);
	for(int i=1;i<=n;i++)
	{
		Mx=-2147483647;
		if(L[b[i]]==-1)m4(1,1,n);
		else
		{
			if(L[b[i]]!=1)m4(1,1,L[b[i]]-1);
//			printf("%d %d %d %d\n",i,Mx,P,R[b[i]]+1);
			if(R[b[i]]!=n)m4(1,R[b[i]]+1,n);
			m2(1,L[b[i]],R[b[i]],1);
		}
		m3(1,P,b[i]); 
//		printf("%d %d %d %d\n",i,P,b[i],Mx);
	}
	puts("YES");
	for(int i=1;i<=n;i++)printf("%d ",ans[i]);
} 

Compiler output:
main.c:5:7: error: variably modified 'a' at file scope
    5 | int n,a[Maxn],b[Maxn],c[Maxn],L[Maxn],R[Maxn],cc[Maxn],ans[Maxn];
      |       ^
main.c:5:15: error: variably modified 'b' at file scope
    5 | int n,a[Maxn],b[Maxn],c[Maxn],L[Maxn],R[Maxn],cc[Maxn],ans[Maxn];
      |               ^
main.c:5:23: error: variably modified 'c' at file scope
    5 | int n,a[Maxn],b[Maxn],c[Maxn],L[Maxn],R[Maxn],cc[Maxn],ans[Maxn];
      |                       ^
main.c:5:31: error: variably modified 'L' at file scope
    5 | int n,a[Maxn],b[Maxn],c[Maxn],L[Maxn],R[Maxn],cc[Maxn],ans[Maxn];
      |                               ^
main.c:5:39: error: variably modified 'R' at file scope
    5 | int n,a[Maxn],b[Maxn],c[Maxn],L[Maxn],R[Maxn],cc[Maxn],ans[Maxn];
      |                                       ^
main.c:5:47: error: variably modified 'cc' at file scope
    5 | int n,a[Maxn],b[Maxn],c[Maxn],L[Maxn],R[Maxn],cc[Maxn],ans[Maxn];
      |                                               ^~
main.c:5:56: error: variably modified 'ans' at file scope
    5 | int n,a[Maxn],b[Maxn],c[Maxn],L[Maxn],R[Maxn],cc[Maxn],ans[Maxn];
      |                                                        ^~~
main.c:9:2: error: variably modified 'tr' at file scope
    9 | }tr[Maxn<<1];
      |  ^~