AT_scpc2026_div2_c.Rearrangement
入门
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer array A=[A1,…,AN] of length N and an integer array B=[B1,…,BM] of length M.
Find a rearrangement of A in which the number of occurrences of B as a contiguous subsequence is maximized. Here, a rearrangement of A means an array A′ satisfying the following condition.
- A′ is an integer array of length N, and there exists a permutation P of 1,…,N such that Ai′=APi(1≤i≤N).
What is a contiguous subsequence? A contiguous subsequence of a sequence is a sequence obtained by taking elements from consecutive positions of the original sequence, in the same order. For example, in the sequence [1,2,3,4], [2,3] is a contiguous subsequence, but [1,3] is not. Multiple contiguous subsequences may overlap with each other in the same sequence. For example, in the sequence [1,2,1,2,1], [1,2,1] appears a total of 2 times. What is a permutation? A permutation of length N is a sequence that contains each integer from 1 to N exactly once. For example, [2,1,4,3] is a permutation, but [4,2,1,1] and [1,2,3,5] are not.
给你一个长度为 N 的整数数组 A=[A1,…,AN] 和一个长度为 M 的整数数组 B=[B1,…,BM]。
请找出 A 的一种重排方式,使得 B 作为连续子序列在该重排数组中出现的次数最多。这里,A 的一个重排是指满足如下条件的整数数组 A′:
- A′ 是一个长度为 N 的整数数组,且存在 1,…,N 的一个排列 P,使得对所有 1≤i≤N,均有 Ai′=APi。
什么是连续子序列?一个序列的连续子序列是指从原序列中连续位置上按原有顺序取出的元素所构成的子序列。例如,在序列 [1,2,3,4] 中,[2,3] 是一个连续子序列,但 [1,3] 不是。同一序列中,多个连续子序列可以互相重叠。例如,在序列 [1,2,1,2,1] 中,[1,2,1] 总共出现了 2 次。
什么是排列?一个长度为 N 的排列是指恰好包含 1 到 N 中每个整数各一次的序列。例如,[2,1,4,3] 是一个排列,而 [4,2,1,1] 和 [1,2,3,5] 都不是。
输入格式
The input is given from Standard Input in the following format:
N M
A1 A2 … AN
B1 B2 … BM
输入从标准输入中按以下格式给出:
N M
A1 A2 … AN
B1 B2 … BM
输出格式
Output the elements of a rearrangement of A that maximizes the number of occurrences of B as a contiguous subsequence, separated by spaces. If there are multiple such rearrangements, output any one of them.
输出数组 A 的一种重排,使得 B 作为连续子序列出现的次数最多,并以空格分隔输出该重排的各元素。如果存在多种满足条件的重排,输出其中任意一种即可。
输入输出样例
输入#1
4 2 1 2 3 4 2 1
输出#1
2 1 3 4
输入#2
4 2 1 2 1 2 2 1
输出#2
2 1 2 1
说明/提示
表示言語
/ /
Constraints
- 1≤M≤N≤1000000
- 0≤Ai,Bi≤1000000
- All given numbers are integers.
表示语言
/ /
限制条件
- 1≤M≤N≤1000000
- 0≤Ai,Bi≤1000000
- 所有给定的数均为整数。
输入解题思路,AI测评打分。不知道怎么写?