307499: CF1365C. Rotation Matching
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Rotation Matching
题意翻译
- 给定两个长度为 $n$ 的 $1\sim n$ 的排列 $a_i,b_i$。 - 你可以对任意一个排列进行若干次长度为 $k$ 的 **循环右移或左移**;这里的循环移动指每个元素依次向左或右移动 $k$ 个,如果移出边界的元素再折回到排列的头或尾。 - 你需要求出在移动过后最多有多少个对应的位置使得 $a_i=b_i$。 - $1\le n\le 2\times 10^5$,$1\le a_i,b_i\le n$。 - translate by @[ShineEternal](https://www.luogu.com.cn/user/45475)。题目描述
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $ n $ . Let's call them $ a $ and $ b $ . Note that a permutation of $ n $ elements is a sequence of numbers $ a_1, a_2, \ldots, a_n $ , in which every number from $ 1 $ to $ n $ appears exactly once. The message can be decoded by an arrangement of sequence $ a $ and $ b $ , such that the number of matching pairs of elements between them is maximum. A pair of elements $ a_i $ and $ b_j $ is said to match if: - $ i = j $ , that is, they are at the same index. - $ a_i = b_j $ His two disciples are allowed to perform the following operation any number of times: - choose a number $ k $ and cyclically shift one of the permutations to the left or right $ k $ times. A single cyclic shift to the left on any permutation $ c $ is an operation that sets $ c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1 $ simultaneously. Likewise, a single cyclic shift to the right on any permutation $ c $ is an operation that sets $ c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1} $ simultaneously. Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.输入输出格式
输入格式
The first line of the input contains a single integer $ n $ $ (1 \le n \le 2 \cdot 10^5) $ — the size of the arrays. The second line contains $ n $ integers $ a_1 $ , $ a_2 $ , ..., $ a_n $ $ (1 \le a_i \le n) $ — the elements of the first permutation. The third line contains $ n $ integers $ b_1 $ , $ b_2 $ , ..., $ b_n $ $ (1 \le b_i \le n) $ — the elements of the second permutation.
输出格式
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
输入输出样例
输入样例 #1
5
1 2 3 4 5
2 3 4 5 1
输出样例 #1
5
输入样例 #2
5
5 4 3 2 1
1 2 3 4 5
输出样例 #2
1
输入样例 #3
4
1 3 2 4
4 2 3 1
输出样例 #3
2