A Equivalent Prefixes

该博客讨论了在两个数组中,当它们具有相同的最小区间查询(RMQ)时,如何找到最大长度的等价前缀。问题描述了一个包含n个不同元素的数组a和b,目标是找到最长的子数组p,使得a的前p个元素和b的前p个元素等价。博客提供了一个示例输入和输出,并暗示可能包含解题代码。

链接:https://ac.nowcoder.com/acm/contest/6362/A
Two arrays u and v each with m distinct elements are called equivalent if and only if RMQ(u,l,r)=RMQ(v,l,r)\mathrm{RMQ}(u, l, r) = \mathrm{RMQ}(v, l, r)RMQ(u,l,r)=RMQ(v,l,r) for all 1≤l≤r≤m1 \leq l \leq r \leq m1≤l≤r≤m
where RMQ(w,l,r)\mathrm{RMQ}(w, l, r)RMQ(w,l,r) denotes the index of the minimum element among wl,wl+1,…,wrw_l, w_{l + 1}, \dots, w_{r}wl​,wl+1​,…,wr​.
Since the array contains distinct elements, the definition of minimum is unambiguous.

Bobo has two arrays a and b each with n distinct elements. Find the maximum number p≤np \leq np≤n where {a1,a2,…,ap}\{a_1, a_2, \dots, a_p\}{a1​,a2​,…,ap​} and {b1,b2,…,bp}\{b_1, b_2, \dots, b_p\}{b1​,b2​,…,bp​} are equivalent.

输入描述:

The input consists of several test cases and is terminated by end-of-file.

The first line of each test case contains an integer n.
The second line contains n integers a1,a2,…,ana_1, a_2, \dots, a_na1​,a2​,…,an​.
The third line contains n integers b1,b2,…,bnb_1, b_2, \dots, b_nb1​,b2​,…,bn​.

* 1≤n≤1051 \leq n \leq 10^51≤n≤105
* 1≤ai,bi≤n1 \leq a_i, b_i \leq n1≤ai​,bi​≤n
* {a1,a2,…,an}\{a_1, a_2, \dots, a_n\}{a1​,a2​,…,an​} are distinct.
* {b1,b2,…,bn}\{b_1, b_2, \dots, b_n\}{b1​,b2​,…,bn​} are distinct.
* The sum of n does not exceed 5×1055 \times 10^55×105.

输出描述:

For each test case, print an integer which denotes the result.

示例1

输入

复制2 1 2 2 1 3 2 1 3 3 1 2 5 3 1 5 2 4 5 2 4 3 1

2
1 2
2 1
3
2 1 3
3 1 2
5
3 1 5 2 4
5 2 4 3 1

输出

复制1 3 4

1
3
4

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
const int N=1e5+10;
ll c[N],n;
struct node{
    int id;
    int x;
    int l;
    int r;
}b[N],a[N];
bool cmp(node p,node q)
{
    return p.x<q.x;
}
bool bmp(node p,node q)
{
    return p.id<q.id;
}
int main()
{
    while(~scanf("%lld",&n))
    {
        for(int i=1;i<=n;i++)
        {
            cin>>a[i].x;
            a[i].id=i;
        }
        for(int i=1;i<=n;i++)
        {
            cin>>b[i].x;
            b[i].id=i;
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=i+1;j<=n+1;j++)
            {
                if(a[i].x>a[j].x||j==n+1)
                {
                    a[i].r=j-1;
                    break;
                }
            }
            for(int j=i-1;j>=0;j--)
            {
                if(a[i].x>a[j].x||j==0)
                {
                    a[i].l=j+1;
                    break;
                }
            }
            for(int j=i+1;j<=n+1;j++)
            {
                if(b[i].x>b[j].x||j==n+1)
                {
                    b[i].r=j-1;
                    break;
                }
            }
            for(int j=i-1;j>=0;j--)
            {
                if(b[i].x>b[j].x||j==0)
                {
                    b[i].l=j+1;
                    break;
                }
            }
        }
        int ans=min(a[1].r,b[1].r);
        for(int i=2;i<=n;i++)
        {
            if(i<=ans)
            {
                ans=min(ans,min(a[i].r,b[i].r));
            }
            else
            {
                if(a[i].l==b[i].l)
                ans=max(ans,min(a[i].r,b[i].r));
                else
                    break;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

 

[root@master ~]# kubeadm config migrate --help This command lets you convert configuration objects of older versions to the latest supported version, locally in the CLI tool without ever touching anything in the cluster. In this version of kubeadm, the following API versions are supported: - kubeadm.k8s.io/v1beta3 Further, kubeadm can only write out config of version "kubeadm.k8s.io/v1beta3", but read both types. So regardless of what version you pass to the --old-config parameter here, the API object will be read, deserialized, defaulted, converted, validated, and re-serialized when written to stdout or --new-config if specified. In other words, the output of this command is what kubeadm actually would read internally if you submitted this file to "kubeadm init" Usage: kubeadm config migrate [flags] Flags: --allow-experimental-api Allow migration to experimental, unreleased APIs. -h, --help help for migrate --new-config string Path to the resulting equivalent kubeadm config file using the new API version. Optional, if not specified output will be sent to STDOUT. --old-config string Path to the kubeadm config file that is using an old API version and should be converted. This flag is mandatory. Global Flags: --add-dir-header If true, adds the file directory to the header of the log messages --kubeconfig string The kubeconfig file to use when talking to the cluster. If the flag is not set, a set of standard locations can be searched for an existing kubeconfig file. (default "/etc/kubernetes/admin.conf") --log-file string If non-empty, use this log file (no effect when -logtostderr=true) --log-file-max-size uint Defines the maximum size a log file can grow to (no effect when -logtostderr=true). Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800) --one-output If true, only write logs to their native severity level (vs also writing to each lower severity level; no effect when -logtostderr=true) --rootfs string [EXPERIMENTAL] The path to the 'real' host root filesystem. --skip-headers If true, avoid header prefixes in the log messages --skip-log-headers If true, avoid headers when opening log files (no effect when -logtostderr=true) -v, --v Level number for the log level verbosity
最新发布
09-12
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值