AT_scpc2026_div2_c.Rearrangement

入门

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an integer array A=[A1,…,AN]A=[A_1,\dots,A_N] of length NN and an integer array B=[B1,…,BM]B=[B_1,\dots,B_M] of length MM.

Find a rearrangement of AA in which the number of occurrences of BB as a contiguous subsequence is maximized. Here, a rearrangement of AA means an array A′A' satisfying the following condition.

  • A′A' is an integer array of length NN, and there exists a permutation PP of 1,…,N1,\dots,N such that Ai′=APi(1≤i≤N)A'_i=A_{P_i}(1 \le i \le 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][1,2,3,4], [2,3][2,3] is a contiguous subsequence, but [1,3][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,2,1], [1,2,1][1,2,1] appears a total of 22 times. What is a permutation? A permutation of length NN is a sequence that contains each integer from 11 to NN exactly once. For example, [2,1,4,3][2,1,4,3] is a permutation, but [4,2,1,1][4,2,1,1] and [1,2,3,5][1,2,3,5] are not.

给你一个长度为 NN 的整数数组 A=[A1,…,AN]A=[A_1,\dots,A_N] 和一个长度为 MM 的整数数组 B=[B1,…,BM]B=[B_1,\dots,B_M]。

请找出 AA 的一种重排方式,使得 BB 作为连续子序列在该重排数组中出现的次数最多。这里,AA 的一个重排是指满足如下条件的整数数组 A′A':

  • A′A' 是一个长度为 NN 的整数数组,且存在 1,…,N1,\dots,N 的一个排列 PP,使得对所有 1≤i≤N1 \le i \le N,均有 Ai′=APiA'_i=A_{P_i}。

什么是连续子序列?一个序列的连续子序列是指从原序列中连续位置上按原有顺序取出的元素所构成的子序列。例如,在序列 [1,2,3,4][1,2,3,4] 中,[2,3][2,3] 是一个连续子序列,但 [1,3][1,3] 不是。同一序列中,多个连续子序列可以互相重叠。例如,在序列 [1,2,1,2,1][1,2,1,2,1] 中,[1,2,1][1,2,1] 总共出现了 22 次。

什么是排列?一个长度为 NN 的排列是指恰好包含 11 到 NN 中每个整数各一次的序列。例如,[2,1,4,3][2,1,4,3] 是一个排列,而 [4,2,1,1][4,2,1,1] 和 [1,2,3,5][1,2,3,5] 都不是。

输入格式

The input is given from Standard Input in the following format:

NN MM
A1A_1 A2A_2 …\dots ANA_N
B1B_1 B2B_2 …\dots BMB_M

输入从标准输入中按以下格式给出:

NN MM
A1A_1 A2A_2 …\dots ANA_N
B1B_1 B2B_2 …\dots BMB_M

输出格式

Output the elements of a rearrangement of AA that maximizes the number of occurrences of BB as a contiguous subsequence, separated by spaces. If there are multiple such rearrangements, output any one of them.

输出数组 AA 的一种重排,使得 BB 作为连续子序列出现的次数最多,并以空格分隔输出该重排的各元素。如果存在多种满足条件的重排,输出其中任意一种即可。

输入输出样例

  • 输入#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≤1 000 0001 \le M \le N \le 1\,000\,000
  • 0≤Ai,Bi≤1 000 0000 \le A_i, B_i \le 1\,000\,000
  • All given numbers are integers.

表示语言

/ /

限制条件

  • 1≤M≤N≤1 000 0001 \le M \le N \le 1\,000\,000
  • 0≤Ai,Bi≤1 000 0000 \le A_i, B_i \le 1\,000\,000
  • 所有给定的数均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页