题解:

把第一个串放好,加一个oo

然后把第二个串倒序放进来

然后就是http://www.cnblogs.com/xuanyiming/p/8510231.html这一题了

代码:

#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long 
const int N=400005;
int m,n,s[N],s1[11],ans[N];
ull h1[N],h2[N],pw[N];
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)scanf("%d",&s[i]);
    scanf("%d",&m);
    s[n+1]=1000000;
    for (int i=1;i<=m;i++)scanf("%d",&s[n+m-i+2]);
    n+=m+1;
    pw[0]=1;
    for (int i=1;i<=n;i++)pw[i]=pw[i-1]*133;
    for (int i=1;i<=n;i++)h1[i]=h1[i-1]*133+s[i];
    for (int i=n;i>=1;i--)h2[i]=h2[i+1]*133+s[i];
    for (int i=1,l1=1,r1=n;i<=n;i++)
     {
        int l=1,r=r1-l1+1;
        while (l<=r)
         {
            int mid=(l+r)>>1;
            if (h1[l1+mid-1]-h1[l1-1]*pw[mid]==h2[r1-mid+1]-h2[r1+1]*pw[mid])l=mid+1;
            else r=mid-1;
         }
        if (l>r1-l1+1)l=1;
        if (s[l1+l-1]>s[r1-l+1])ans[i]=s[r1],r1--;
        else ans[i]=s[l1],l1++;
     }
    for (int i=1;i<n;i++)printf("%d ",ans[i]);
    return 0;
}   

 

posted on 2018-03-05 19:05  宣毅鸣  阅读(116)  评论(0编辑  收藏  举报